Socket
.net中对Socket通信进行了封装,使用起来也是很方便的,只需要记住服务器和客户端的基本操作流程,在写代码时注意一点就行了,图片来自黑马教学视频的截图,作为参考,记录在此。
记录一些简单的code:
1.服务器端
Socket socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp);
IPAddress ip;
if (IPAddress.TryParse(txtIp.Text, out ip))
{
try
{
IPEndPoint point = new IPEndPoint(ip, Convert.ToInt32(txtPort.Text));
socketWatch.Bind(point);
ShowMsg("监听成功!");
socketWatch.Listen(10);
Thread th = new Thread(Listen);
th.IsBackground = true;
th.Start(socketWatch);
}
catch { }
}
void Listen(object o)
{
Socket socketWatch = o as Socket;