tcpconnection.cs

来自「C#实现的网络编程实验聊天程序(含论文)」· CS 代码 · 共 38 行

CS
38
字号
using System;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace EasyChat
{
    /// <summary>
    /// TCP连接类,成功连接返回TcpClient引用,否则返回null
    /// </summary>
    class TCPConnection
    {
        private IPAddress _ip = null;
        private int _port;
        private TcpClient _tcpc = null;

        public TCPConnection(IPAddress ip, int port)
        {
            _ip = ip;
            _port = port;
        }

        public TcpClient Connect()
        {
            try
            {
                _tcpc = new TcpClient();
                _tcpc.Connect(_ip, _port);
            }
            catch (Exception)
            {
                return null;
            }
            return _tcpc;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?