TCP Sockets for C # (synchronous mode)

Source: Internet
Author: User

Server-side:

Port for listening ports
Byte[] BS generally declares a larger array to receive
int Ilen is the received packet length, according to it from byte[] BS intercept is good
IPEndPoint Localendpoint =NewIPEndPoint (Ipaddress.parse ("127.0.0.1"), port); Socket Listener=Newsockets (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp); listener. Bind (localendpoint); listener. Listen ( -); while(true) {Socket sock=Listener.    Accept (); byte[] bs =New byte[1024x768*1024x768]; intIlen =sock. Receive (BS);}

Client:

It's easy to send data after a successful connection.

New IPEndPoint (Ipaddress.parse (IP), iport); // IP and Ports New sockets (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp); sock. Connect (IPEP); sock. Send (Sendbytes, Sendbytes.length, socketflags.none); // Send Message

TCP Sockets for C # (synchronous mode)

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.