"Socket" a minute to clear the socket Udpsocket tcpsocket tcplistener tcpclient and UdpClient

Source: Internet
Author: User

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:

    1. IPAddress HostIP = new ipaddress.parse ( "remote computer IP address");
    2. IPEndPoint host = new ipendpoint (HostIP, 8080);
    3. Udpclient.send ( "Bytes Sent", "Bytes Sent", host);

Service side:

    1. Server = new udpclient ();
    2. Receivepoint = new ipendpoint (new IPAddress ( "127.0.0.1"), 8080);
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.