The socket Socket interface is the basis for network operation of TCP UDP in various languages.
Directly with the socket object development can choose Udpsocket or Tcpsocket, the two in use only a few methods and parameters, all the bottom is the socket to help us achieve
UDP Focus:
{
Client:
Socket client = new socket (addressfamily.internetwork, Sockettype.dgram, PROTOCOLTYPE.UDP);
Service side:
Socket. The ReceiveFrom receives the datagram to the data buffer and stores the endpoint.
No listening, only one endpoint.
}
TCP Focus:
{
Client:
Socket c = new socket (addressfamily.internetwork, SocketType.Stream, protocoltype.tcp); Create a socket
C.send (BS, BS. Length, 0); Send Message
Service side:
bytes = socket. Receive (Recvbytes, Recvbytes. Length, 0);//Receive information from the client
Listen, keep listening.
}
------------------------------
TcpListener is the encapsulation of sockets, making it easier for users to achieve simple business requirements
Mylistener.accepttcpclient ();
Heard of Udplistener, of course not, UDP itself is not listening
Like TcpClient and UdpClient and Tcplinster, This is also a simplification of the socket.
TcpClient and Tcplinster together.
UdpClient and UdpClient together.
{
Client:
- IPAddress HostIP = new ipaddress.parse ( "remote computer IP address");
- IPEndPoint host = new ipendpoint (HostIP, 8080);
- Udpclient.send ( "Bytes Sent", "Bytes Sent", host);
Service side:
- Server = new udpclient ();
- Receivepoint = new ipendpoint (new IPAddress ( "127.0.0.1"), 8080);
- byte [] Recdata = server. Receive ( ref receivepoint);
}
Very simple! The next step is to clarify some of the advanced uses of the socket
Socket for a minute to clear the socket Udpsocket tcpsocket tcplistener tcpclient and UdpClient