Sample Download C# version: http://code.msdn.microsoft.com/CSSocketCommunication-089f0e86 VB version: http://code.msdn.microsoft.com/VBSocketCommunication-f1fb4541
Today’s code sample demonstrates the basic socket network communication in C# and VB. Sockets are an application programming interface (API) in an operating system, used for in inter-process communication. Sockets constitute a mechanism for delivering incoming data packets to the appropriate application process or thread, based on a combination of local and remote IP addresses and port numbers. Each socket is mapped by the operational system to a communicating application process or thread. .NET supplies a Socket class which implements the Berkeley sockets interface. It provides a rich set of methods and properties for network communications. The Socket class allows you to perform both synchronous and asynchronous data transfer using any of the communication protocols listed in the ProtocolType enumeration.
You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.
Sockets are an application programming interface (API) in an operating system, used for in inter-process communication. Sockets constitute a mechanism for delivering incoming data packets to the appropriate application process or thread, based on a combination of local and remote IP addresses and port numbers. Each socket is mapped by the operational system to a communicating application process or thread.
There are some limitations on this sample:
1. Due to the socket buffer size, the string message including EOM marker shouldn't bigger than 1024 bytes when encoded to bytes by Unicode. 2. The sample is designed for receiving and sending only one string message.
To overcome the limitations above, the developer need handle message separating and merging operations on socket buffer.
1. Create a socket to listen the incoming TCP connection. 2. After get the client connection,asynchronously receive the data and listen the TCP connection again. 3. Finishing receiving data, send the response to client process. 4. If user inputs the word quit to exit the program
Socket Class http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
Asynchronous Server Socket Example http://msdn.microsoft.com/en-us/library/fx6588te.aspx
Chapter4: Using Sockets of Professional .NET Network Prgromming http://www.amazon.com/Professional-Network-Programming-Srinivasa-Sivakumar/dp/1861007353
Thank you, this samples are very helpful.
A simple socket programming example....