C# Socket 服务监听  客户端怎么去连接 如何长期保持这种连接?
先谢!

解决方案 »

  1.   

    this.m_IP = server;//IP或机器名
    this.m_Port = port;//端口号
    IPHostEntry hostEntry = Dns.GetHostEntry(this.m_IP);IPEndPoint ipe = new IPEndPoint(hostEntry.AddressList[0], this.m_Port);
    this.m_Socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
    try
    {
    this.m_Socket.Connect(ipe);
    }
    catch
    { }this.m_Socket可以做为连接后的全局Socket,除非断开连接,否则一直处于连接状态。