Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Socket programming in C#


Published on

fundemental of socket programming in C#

Published in: Software
  • Be the first to comment

Socket programming in C#

  1. 1. Socket Programming with C#
  2. 2. Windows Socket • Windows 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.
  3. 3. Server vs Client • Server: Listen on a port • Client: Connect to server If the server is not “Listening” then client can not connect to it.
  4. 4. Server steps Create a socket. Bind the socket. Listen on the socket for a client. Accept a connection from a client. Receive and send data. Disconnect.
  5. 5. Client steps Create a socket. Connect to the server. Send and receive data. Disconnect.
  6. 6. C# socket class class 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.
  7. 7. Synchronous and Asynchronous Many 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.