CSharp.Net-Informations.com

  How to C# Socket programming




   Categories

    HOME
    VB.NET
    CSHARP


   














How to C# Socket programming

C# simplifies the network programming through its namespaces like System.Net and System.Net.Sockets . A Socket is an End-Point of To and From (Bidirectional) communication link between two programs (Server Program and Client Program ) running on the same network . We need two programs for communicating a socket application in C#. A Server Socket Program ( Server ) and a Client Socket Program ( Client ) .

C# Server Socket Program: A C# Server Socket Program running on a computer has a socket that bound to a Port Number on the same computer and listening to the client's incoming requests.

C# Client Socket Program: A C# Client Socket Program have to know the IP Address ( Hostname ) of the computer that the C# Server Socket Program resides and the Port Number assign for listening for client's request .

Once the connection is established between Server and Client , they can communicate (read or write ) through their own sockets.

csharp-server-client-socket

There are two types of communication protocol uses for Socket Programming in C# , they are TCP/IP ( Transmission Control Protocol/Internet protocol ) Communication and UDP/IP ( User Datagram Protocol/Internet protocol ) Communication .

In the following section we are going to communicate a C# Server Socket Program and C# Client Socket Program using TCP/IP Communication Protocol.

csharp-server-client-socket-program

The above picture shows a Server and Client communication interfaces in C#.

C# Server Socket Program:

The Server Socket Program is done through a C# Console based application . Here the Server is listening for the Client's request , and when the C# Server gets a request from Client socket , the Server sends a response to the Client . Click the following link to see in detail of a C# Server Socket Program.

C# Client Socket Program:

The C# Client Socket Program is a windows based application . When the C# Client program execute , it will establish a connection to the C# Server program and send request to the Server , at the same time it also receive the response from C# Server . Click the following link to see in detail of C# Client Socket Program.

How to run this program ?

The C# Socket Program has two sections.

1. C# Server Socket Program

2. C# Client Socket Program

When you finish coding and build the Server and Client program , First you have to start C# Server Socket Program from DOS prompt , then you will get a message "Server Started" in your DOS screen, where the server program is running .

Next step is to start C# Client Socket Program in the same computer or other computers on the same network . When you start the client program , it will establish a connection to the Server and get a message in client screen " Client Started " , at the same time you can see a message in the Server screen "Accept connection from client" .

Now your C# Server Socket Program and C# Client Socket Program is get connected and communicated . If you want to communicate the Server and Client again , click the button in the client program , then you can see new messages in the Server and Client programs displayed.


        
        
C# Tutorial


CSharp Communications Related Contents
*     How to send email from C#
*     How to send email with attachment from C#
*     How to send html email from C#
*     How to send cdo email from C#
*     How to find hostname of a computer
*     How to find IP Adress of a computer
*     How to read URL Content from webserver
*     C# Server Socket program
*     C# Client Socket program
*     C# Multi threaded socket programming
*     C# Multi threaded Server Socket programming
*     C# Multi threaded Client Socket programming
*     How to C# Chat server programming
*     How to C# Chat Server
*     How to C# Chat Client

CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved