日期:2014-05-18  浏览次数:21050 次

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

------解决方案--------------------
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,除非断开连接,否则一直处于连接状态。
------解决方案--------------------
1楼对的哦

记得另开一个线程连接,不然会假死的.