7
Socket Programming with C#

Socket programming in C#

Embed Size (px)

Citation preview

Socket Programming with C#

Socket Programmingwith C#Windows SocketWindows Sockets 2 (Winsock) enables programmers to create advanced Internet, intranet, and other network-capable applications to transmit application data across the wire, independent of the network protocol being used.Server vs ClientServer: Listen on a portClient: Connect to server

If the server is not Listening then client can not connect to it.Server stepsCreate a socket.Bind the socket.Listen on the socket for a client.Accept a connection from a client.Receive and send data.Disconnect.Client stepsCreate a socket.Connect to the server.Send and receive data.Disconnect.

C# socket classclass TcpListener : Listens for connections from TCP network clients.class TcpClient : Provides client connections for TCP network services.class UdpClient : Provides User Datagram Protocol (UDP) network services.NetworkStream :Provides the underlying stream of data for network access.SocketException The exception that is thrown when a socket error occurs.Synchronous and AsynchronousMany applications call methods asynchronously because it enables the application to continue doing useful work while the method call runs.

An asynchronous client socket does not suspend the application while waiting for network operations to complete.

Synchronous call return immediately without waiting for the method to finished.