C# app receives message on socket (CSSocketServer)

The VC# code sample demonstrates creating a socket object to listen to the incoming connections. CSSocketClient and CSSocketServer show the basic socket programming.

C# (52.4 KB)
3.7 Star
12,182 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
    CONSOLE APPLICATION : CSSocketClient Project Overview


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. It supplies the following types of socket:

Stream: Supports reliable, two-way, connection-based byte streams without 
the duplication of data and without preservation of boundaries.

Dgram:Supports datagrams, which are connectionless, unreliable messages of
a fixed (typically small) maximum length. 

Raw: Supports access to the underlying transport protocol.Using the 
SocketTypeRaw, you can communicate using protocols like Internet Control 
Message Protocol (Icmp) and Internet Group Management Protocol (Igmp). 

Rdm: Supports connectionless, message-oriented, reliably delivered messages, 
and preserves message boundaries in data. 

Seqpacket:Provides connection-oriented and reliable two-way transfer of 
ordered byte streams across a network.

Unknown:Specifies an unknown Socket type.


Silverlight 3 Tools for Visual Studio 2008 SP1

Silverilght 3 runtime:

Project Relation:

CSSocketClient <--> CSSocketServer
CSSocketServer is the server process to communicate the client process
via the Socket.

Code Logic:

1. Create a socket to connect the TCP Socket endpoint.

2. After get the connection, send the data to the server process.

3. Receive the response of the server process.

4. Shut down the TCP connection and release the Socket resource.


Chapter4: Using Sockets of Professional .NET Network Prgromming

Socket Class

Asynchronous Server Socket Example