C#
TCPServer
1、使用的通讯通道:socket
2、用到的基本功能:
Bind,
Listen,
BeginAccept
EndAccept
BeginReceive
EndReceive
3、函数参数说明
listener.Bind(localEndPoint);
localEndPoint
//new
//IPAdress.Parse("192.168.1.3")
listener.Listen(100);
监听
Socket
完成连接,返回此时的socket通道。
handler.BeginReceive(state.buffer,
接收的字节,0,字节长度,0,接收时调用的回调函数,接收行为的容器。
========
容器的结构类型为:
Code
- public
class StateObject - {
-
// Client socket. -
public Socket workSocket = null; -
// Size of receive buffer. -
public const int BufferSize = 1024; -
// Receive buffer. -
public byte[] buffer = new byte[BufferSize]; -
// Received data string. -
public StringBuilder sb = new StringBuilder(); - }
容器至少为一个socket类型。
===============
完成一次连接。数据存储在state.buffer里,bytesRead为读取的长度。
handler.BeginSend(byteData,