Building a simple server client application using C#

Hello everybody! Here I am again to show you a simple, or maybe I can say the simplest way to build a server client application using C#. I said last time I would write a Rails code, but, promise to do that next time.

It’s just a bunch of lines and there you go, you already have your application running, you can test both (server and client) on your computer, or if you have another one, you can test and play with it too.

After the tutorial, I’ll let the whole code for you to download. But before that I will go through it step by step, trying to make things clear.

server_client

So, stop the chit chat and let’s get some work done!

First I’m going to explain the server code, and when it’s already running we jump into our client, which in this case I’ll consider only one, but nothing prohibits you to connect more than one client to you server.

By the way, I’m using Visual Studio 2010 and Windows 7.

Step 1: Create your C# application.

Step 2: You will need those LOC at the top.

1 using System; 2 using System.Text; 3 using System.Net; 4 using System.Net.Sockets;

Step 3: Everything must be inside a “try… catch…” block. So, you now create an IPAdress using your own IP, a TcpListener which will get your clients and then start it.

1 IPAddress ipAdress = IPAddress.Parse("172.21.5.99"); 2 // You can use local IP as far as you use the 3 //same in client 4 5 // Initializes the Listener 6 TcpListener myList = new TcpListener(ipAdress,8000); 7 8 // Start Listeneting at the specified port 9 myList.Start();

Step 4: Showing a message to the user is important, so:

1 Console.WriteLine("Server running - Port: 8000"); 2 Console.WriteLine("Local end point:" + 3 myList.LocalEndpoint ); 4 Console.WriteLine("Waiting for connections...");

Step 5: Now that your list is already running, you’re waiting for a connection, when it does, you must treat it creating a socket that will get the client.

1 Socket s = myList.AcceptSocket(); 2 // When accepted 3 Console.WriteLine("Connection accepted from " 4 + s.RemoteEndPoint); 5 6 byte[] b = new byte[100]; 7 int k = s.Receive(b); 8 Console.WriteLine("Recieved..."); 9 10 for (int i=0;i<k;i++) 11 { 12 Console.Write(Convert.ToChar(b[i])); 13 }

Step 6: Besides sending a message to the user that the server is already running, it’s also important to send an automatic message back to the client, so it does know that the connection was succeeded.

1 ASCIIEncoding asen = new ASCIIEncoding(); 2 s.Send(asen.GetBytes("Automatic message: 3 + "String received by server!")); 4 Console.WriteLine("\n Automatic message sent!");

Step 7: Finally close the socket and stop the list.

1 s.Close(); 2 myList.Stop();

Step 8: You can treat the “catch” the way you prefer, I just went for throwing a message.

1 Console.WriteLine("Error..... " + e.StackTrace);

Well, since we have now our server running perfectly, let’s build the client.

Step 1: Similar to your server, the client will need:

1 using System; 2 using System.IO; 3 using System.Net; 4 using System.Text; 5 using System.Net.Sockets;

Step 2: Alright, do not forget to build your code inside a “try… catch…”, you will need now a TcpClient and a Stream, so follow the code below:

1 TcpClient tcpclnt = new TcpClient(); 2 Console.WriteLine("Connecting....."); 3 4 tcpclnt.Connect("172.21.5.99",8001); 5 // Use the ipaddress as in the server program 6 7 Console.WriteLine("Connected..."); 8 Console.Write("Enter the string to be sent: "); 9 10 String str = Console.ReadLine(); 11 Stream stm = tcpclnt.GetStream();

Step 3: Remember that when we got the message from our client we converted from ASCII, so to send a message we sure must convert to it.

1 ASCIIEncoding asen = new ASCIIEncoding(); 2 byte[] ba = asen.GetBytes(str); 3 Console.WriteLine("Sending..."); 4 5 stm.Write(ba,0,ba.Length); 6 7 byte[] bb = new byte[100]; 8 int k = stm.Read(bb,0,100); 9 10 for (int i = 0;i < k; i++) 11 { 12 Console.Write(Convert.ToChar(bb[i])); 13 }

Step 4: Finally, close your TcpClient:

1 tcpclnt.Close();

Step 5: And the “catch” block:

1 Console.WriteLine("Ops! Error! " + e.StackTrace);

Voila! You now have a simple server client application. Note that it’s just a connection and messages send, you can play with your code, finding out new features and adapting it to your need.

Hope you have enjoyed!

Thanks for all the attention.

3_NET_logo

111 comments

    1. Oh, Im so sorry. It seems I lost the .rar in my computer. I should have uploaded on Dropbox. Did you have any trouble with the tutorial? Feel free to ask.
      Regards.

      1. Hi fpgentil,
        may i know how to connect a single server into more number of clients and also i wants to see client information(photos,some data) from server…….

      2. Hello vinith,

        Well, i can think of two ways to do that.
        1. You can connect each client to one port of your server. For example, you can create a list of TcpListeners.

        2. Or you can use the same port for all clients and control the connections, the disadvantage is that you lose multiple access at the same time from different clientes.

        About sharing photos, data, can you be more specific? Feel free to contact me via email, facebook, the way you want.

        Regards,
        Felipe

      3. Hey man, I lost this code. As mentioned I should have uploaded on my Dropbox. Did you have any kind of problem with the tutorial? Feel free to ask.

        Regards,
        Felipe

      4. Mate I believe these program running TCP/IP on C#! How about if I wanted to use UDP for the same program what do I need to change? sorry am a newbie in this language and I would be appreciated if you can help. Thanks

  1. may i know how to connect a single server into more number of clients and also i wants to see client information(photos,some data) from server…….

    1. Hello ma,

      Well, can you be more specific? What you mean by give you the code for client server using based application? Do you want the whole application?

      Regards,
      Felipe

    1. Hello,

      Well, if you want to connect more clients to a single server, I recommend you to use each client per port. I’ve done something similar at work, but I do not have the code anymore. If you want to, I can help you.

      Regards,
      Felipe

      1. sir can i have also the code…. and one more thing what if the database is in oracle? because we are having a hard time in printing coz the path is changing… please help us…. thank you in advance…. i will wait for ur answer…

      2. Hello jec,

        I’m sorry but it seems I don’t have the code anymore, but it’s pretty simple. About the the database, what exactly are you trying to do? Which path is changing? If you could explain me better perhaps I might be able to help you.

        Regards,
        Felipe

  2. Hello Felipe,

    I am Kimsros, I want to develop Digital Signage System, but i no have any experience with C# programming.

    I am starting to learn about it by searching through the Internet.

    For example I have 3 clients.

    So i want my Server program upload:

    – File Playlist1 to Client 1

    – File Playlist2 to Client 2

    – File Playlist3 to Client 3

    Inside the File Playlist is stored the Start Date/End Date and path where i kept file Video, Image.

    Could you please give me the sample code for Client/Server in C# using Windows Form Application?

    Thanks in advanced,

    Kimsros

      1. Hello Felipe,

        I am using TCP. Please let me try with your example.

        Thank you so much.

        Best regards,
        Kimsros

      2. Hello Felipe,

        Do you have tutorial using TCP protocol? What are different between UDP or TCP?

        I want to transfer my Playlist file from server program to client, so that the client will play this playlist.

        Thanks in advanced,

        Regards,
        Kimsros

      3. hy…
        i developed c# application in which different user with different rights (staff, admin, account, hod & etc).. i am using c# with oracle 11g… nothing problem atall during designing and developing…. after completion of project end user want a client server architecture 😦 now what i can do… plzzzz help me send direct message (softmise@gmail.com) i am very thankful in advance….

  3. Hello there, I am a beginner and this basic tutorial really improved my understanding. But I have to ask. Do I have to create a new class file and put it inside another public static void Main for the client code? I can’t seem to run them.. Also what does e in e.StackTrace stand for? The program cant read e. 😦

    1. Hello JE,

      Feel free to be in touch whenever you need to.
      Actually you don’t have to create a new class for the client. You can build two separated projects, one for the client and the other for the server itself.

      StackTrace is a .NET Class, you can read more about it here:
      http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx

      About the e, it’s raising you an error because there’s not e declared, e should be “Exception e” declared in your try/catch statement.

      Regards,
      Felipe

  4. I’m only getting the catch exception 😦 I tried doing it on visual C# and used richtextboxes to display the text. Why can’t I also show two forms at once? 😦

    1. Hello again JE,

      Which error are you getting with the try/catch?
      You can simply use textBox to display the text, and to show 2 forms at one, all you have to do is instantiate two forms and call its show() method.

      Regards,
      Felipe

  5. Hi I’m getting the error at the myList.Start() saying that the IP is invalid wherein I used my IP for both of the forms..

  6. Thanks for this! I’ve been trying to get on board with client / server connections and this has put me in the right direction! Thanks again! 😀

    1. Hello,

      May you please reask your question? I didn’t understand properly what kind of example do you want me to give.
      Thanks in advance.

      Regards,
      Felipe

    1. Hello,

      Basically if you follow the tutorial you will be able to send a file, all you have to do is convert itself into a byte array which you can use this:
      byte[] bytes = System.IO.File.ReadAllBytes(filename);

      Hope it helps.
      Regards and good luck,
      Felipe

      1. What do you mean by data table, Ahmed?
        You can send everything that can be converted to byte[] and do the inverse process on the other part.

        Regards,
        Felipe

  7. Hello ,
    sir i am having a text file which is being modified after every two hour. I want to upload that text file on server. Please help me out to find the solution in c# application.
    Thanks
    Regards
    Krishna Agarwal

    1. Hello Krishna,

      To send or upload a file you must convert it into a byte array, you can use this:
      byte[] bytes = System.IO.File.ReadAllBytes(filename);
      I believe it will solve your problem.

      Hope it helps, feel free to contact me whenever you need.
      Regards and good luck,
      Felipe

  8. hello felipe,
    i have a graduation project from the university. my teacher wants an application using http to connect the servers which are used for different purposes. one of server is for sms server which takes only text area sent by users to return it to application. this is a part of my project. how i try to adapt your codes here into my project or how can i find a solution to finish this part ?

    1. Hello hamit,

      Well, my code is not very similiar to what you need exactly.
      But tell me more about it, should it be in c#?
      Simple http connection with the server (is the server already implemented?)
      Feel free to mail or skype me, maybe I can be more helpful

      Regards,
      Felipe

      1. hello felipe,
        skype might be a good solution but how can i reach your skype to talk about our graduation project clearly ?
        good works

  9. Hello fpgentil!
    Thanks for this usefull sharing. I am wondering that how can we create client-server application between ubuntu(server) and windows(client & to adept in c# based system)? If you enlighten me about this i would be very appreciated.

    1. Hello erami,

      In fact, it depends on which way to communicate you are using, it doesn’t matter so much the platform.
      I’ve done some client-server applications between windows (c#) and android and it worked as a charm.

      I used sockets in both to share messages and also JSON to serialization.

      Tell me more about what you want to do and I can be more specifc.

      Good luck
      Regards,
      Felipe

      1. Hi fpgentil,

        Basically, I need to create a communication line between 2 different computer. First one is using windows as os and second one is working on Ubuntu. So, using TCP-IP with socket programming I need to establish that communication. Ubuntu should be the server part and I need to take some data from one software written by c++ to send Windows part which will be the client and client part should be written in c#.

        Regards

      2. Hello erami,

        Well, based on your explanation, it will work smoothly. Have you implemented your c++ server already? I recommend you to use a program called Wireshark to help you out.

        I have never worked with TCP in C++, but I’m sure it will work as a charm for you 🙂

        Feel free to ask more!
        Regards,
        Felipe

    1. Hi Ramachandr,

      I’m sorry but it seems that I’ve lost the source code in my computer, but if you have any trouble with it feel free to ask.

      Regards,
      Felipe

  10. Hello fpgentil,
    my self salman,
    i am the beginner in c#.. I have developed an application where in,if a system goes idle for some time a form appears asking the reason why system was idle and the reason the user provide will be stored in systems local file….i want to implement the same application on network,so that if a user gives some reason it should get stored in a server connected to it…how to proceed…. and the problem with my existing app is that the system should have .net frame work installed….is it possible to write a c# app run on the system with out any .net frame work?if not then how to proceed?
    thanks… 🙂

    1. Hello salman,

      For instance, a C# application does not run without .NET framework. If you don’t or can’t have .NET I recommend you to take a look at a different language.

      Well, back to your project. I understood the local problem but not the version over the network.

      Correct me if I’m wrong:
      The system will be connected to a server (both running your app), if a system is idle for some reason it should communicate with the server and send a message. Something like that?

      Regards,
      Felipe

  11. hy thanks bro for this server,i just want to know how to implement client in android to connect to server in csharp

    1. Hello hassaan,

      The principle is the same, I have developed an application in Android to communicate with a server in C#.

      That’s a brief example:

      public static DatagramSocket s;

      InetAddress local = InetAddress.getByName(IP_SERVER);
      DatagramPacket p = new DatagramPacket(MESSAGE, MESSAGE.length, local, SERVER_PORT);

      s = new DatagramSocket(objPedidoXML.Porta);
      s.send(p);

      pretty simple, huh?
      Feel free to keep in touch.

      Regards,
      Felipe

      1. bro thanks for reply,,,can u please send me the complete code of csharp server and android client? i need to implement it to my final year project,,,please ,il be grateful
        my email onlyme843@hotmail.com…regardz

  12. Hi
    i am developing client server application using C# windows from.I am able to send a single a message from client to server and then the response from server to client but the problem is that i cannot able to send multiple messages from client to server.Can u help me.Here is my Server code:

    public ManualResetEvent allDone = new ManualResetEvent(false);
    public class StateObject
    {
    public Socket workSocket = null; // Client socket.

    public const int BufferSize = 1024; // Size of receive buffer.
    public byte[] buffer = new byte[BufferSize]; // Receive buffer.
    public StringBuilder sb = new StringBuilder(); // Received data string.
    }
    public class AsynchronousSocketListener
    {
    public ManualResetEvent allDone = new ManualResetEvent(false); // Thread signal

    public void AcceptCallback(IAsyncResult ar)
    {
    allDone.Set(); // Signal the main thread to continue.

    Socket listener = (Socket)ar.AsyncState; // Get the socket that handles the client request.
    Socket handler = listener.EndAccept(ar);

    StateObject state = new StateObject(); // Create the state object.
    state.workSocket = handler;
    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);

    }

    public void ReadCallback(IAsyncResult ar)
    {
    String content = String.Empty;

    StateObject state = (StateObject)ar.AsyncState; // Retrieve the state object and the handler socketfrom the asynchronous state object.

    Socket handler = state.workSocket;

    int bytesRead = handler.EndReceive(ar); // Read data from the client socket.

    if (bytesRead > 0)
    {
    state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); // There might be more data, so store the data received so far.

    content = state.sb.ToString(); // Check for end-of-file tag. If it is not there, read more data.

    if (content.IndexOf(“”) > -1)
    {
    // All the data has been read from the client. Display it.
    Send(handler, content);
    MessageBox.Show(content);
    }
    else
    {

    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state); // Not all data received. Get more.

    }

    }

    }

    private void Send(Socket handler, String data)
    {
    data = “bye”;
    byte[] byteData = Encoding.ASCII.GetBytes(data); // Convert the string data to byte data using ASCII encoding.

    handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler); // Begin sending the data to the remote device.

    }

    private void SendCallback(IAsyncResult ar)
    {

    try
    {
    Socket handler = (Socket)ar.AsyncState; // Retrieve the socket from the state object.
    int bytesSent = handler.EndSend(ar); // Complete sending the data to the remote device.

    handler.Shutdown(SocketShutdown.Both);
    handler.Close();

    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    }

    }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void Form1_MouseClick(object sender, MouseEventArgs e)
    {

    byte[] bytes = new Byte[1024]; // Data buffer for incoming data.

    IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());

    IPAddress ipAddress = ipHostInfo.AddressList[0];

    IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8888);

    Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Create a TCP/IP socket.

    try // Bind the socket to the local endpoint and listen for incoming connections.
    {
    listener.Bind(localEndPoint);

    listener.Listen(100);

    while (true)
    {
    allDone.Reset(); // Set the event to nonsignaled state.

    AsynchronousSocketListener na = new AsynchronousSocketListener();

    listener.BeginAccept(new AsyncCallback(na.AcceptCallback), listener);

    allDone.WaitOne(); // Wait until a connection is made before continuing.

    }

    }
    catch (Exception es)
    {
    MessageBox.Show(es.ToString());
    }
    }

    Here is my Client Code:

    private static ManualResetEvent connectDone = new ManualResetEvent(false);
    private static ManualResetEvent sendDone = new ManualResetEvent(false);
    private static ManualResetEvent receiveDone = new ManualResetEvent(false);
    private static String response = String.Empty;
    private void Form1_Load(object sender, EventArgs e)
    {
    }
    public class StateObject
    {
    public Socket workSocket = null; // Client socket.
    public const int BufferSize = 256; // Size of receive buffer.
    public byte[] buffer = new byte[BufferSize]; // Receive buffer.
    public StringBuilder sb = new StringBuilder(); // Received data string.

    }
    public class AsynchronousClient
    {
    }
    private void ConnectCallback(IAsyncResult ar)
    {
    try
    {
    Socket client = (Socket)ar.AsyncState; // Retrieve the socket from the state object.
    client.EndConnect(ar); // Complete the connection.
    // Console.WriteLine(“Socket connected to {0}”, client.RemoteEndPoint.ToString());

    label2.Text = client.RemoteEndPoint.ToString();
    connectDone.Set(); // Signal that the connection has been made.
    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    }
    }
    private static void Receive(Socket client)
    {
    try
    {
    StateObject state = new StateObject(); // Create the state object.
    state.workSocket = client;
    client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); // Begin receiving the data from the remote device.

    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    }
    }
    private static void ReceiveCallback(IAsyncResult ar)
    {
    try
    {
    StateObject state = (StateObject)ar.AsyncState; // Retrieve the state object and the client socket from the asynchronous state object.
    Socket client = state.workSocket;
    int bytesRead = client.EndReceive(ar); // Read data from the remote device.

    if (bytesRead > 0)
    {
    state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); // There might be more data, so store the data received so far.
    client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); // Get the rest of the data.

    }
    else
    { // All the data has arrived; put it in response.
    if (state.sb.Length > 1)
    {
    response = state.sb.ToString();
    }
    receiveDone.Set(); // Signal that all bytes have been received.

    }

    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    }

    }
    private static void Send(Socket client, String data)
    {
    byte[] byteData = Encoding.ASCII.GetBytes(data); // Convert the string data to byte data using ASCII encoding.
    client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client); // Begin sending the data to the remote device.
    }
    private static void SendCallback(IAsyncResult ar)
    {
    try
    {
    Socket client = (Socket)ar.AsyncState; // Retrieve the socket from the state object.
    int bytesSent = client.EndSend(ar); // Complete sending the data to the remote device.
    sendDone.Set(); // Signal that all bytes have been sent.
    }
    catch (Exception e)
    {
    MessageBox.Show(e.ToString());
    }
    }

    private void button1_Click(object sender, EventArgs e)
    {
    try
    {

    // Establish the remote endpoint for the socket.The name of the remote device is “host.contoso.com”.

    int port = 8888;
    IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
    IPAddress ipAddress = ipHostInfo.AddressList[0];

    IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
    Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Create a TCP/IP socket
    client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); // Connect to the remote endpoint.
    connectDone.WaitOne();

    // Send test data to the remote device.
    Send(client, textBox1.Text + “”);
    sendDone.WaitOne();

    Receive(client); // Receive the response from the remote device.
    receiveDone.WaitOne();

    label1.Text = response; // Write the response to the console.
    // client.Shutdown(SocketShutdown.Both); // Release the socket.
    // client.Close();
    }
    catch (Exception es)
    {
    MessageBox.Show(es.ToString());
    }
    }

    Thanks in advance

    1. Hello Saeed,

      It seems to work fine, but the problem might be the way you are handling the async call.

      Try to call your BeginReceive method outside the if clause. (Line 193).

      Regards,
      Felipe

  13. i have a question regarding client server application.
    in case of a chat server application . how to manage multiple clients . should multiple clients be started on separate threads. is there a limit to the no. of clients that can be handled.
    i read many codes on stack overflow and codeproject. could come to a conclusion.

    Thanks in advance 🙂

    1. Hello vinay,

      Handling multiple clients is not that hard, I’ve come up with a solution that worked for me, all I had to do was bind the server socket to any ip address like this:

      ipEndPointServer = new IPEndPoint(IPAddress.Any, 60000);

      And I could receive messages from multiple clients. There’s actually not a max number of clients I believe.

      Regards,
      Felipe

  14. hi sir
    i need to create a application using tcp client and server …….

    there is 2 client communicate server for different job

    client 1 —– communicate for addition
    client 2—— communicate for subtract

    and handle all request for same time using multithreading

    and responses for each client

    and calculate client processing time low process time give first

    please send me code for my id arunkarthi25@gmail.com

    1. That shouldn’t be hard to implement.
      Have you tried to follow my tutorial?

      Let me know if you have any specific code trouble and I’ll try to help you out.

      Regards,
      Felipe

  15. hi …
    thanks for u r replay

    ya i tried some example ..but i need to know the multi thread server concept using one are more thread in same client …..

    thread 1 perform one job
    thread 2 perform one job
    server calculate thread timing and display the result

    1. Hello karthikeyan,

      Do you know how to use Threads in C#? It’s pretty simple, I can help you if you have any problems with them.

      Regards,
      Felipe

  16. HI,
    I want to send data from database from server to client.For example if client send a query for customer record,the data/table of customer is send to client which is shown to client in datagridview. .

    1. Hello Saeed,

      Basically its the same principle, you make your request, get your data and send it to client. There are plenty ways to do that, tell me if you have problems with this code and I’ll help you.

      Regards,
      Felipe

  17. Hello!
    I want to create ASP.NET client server application in which server send a email to the client and the client receives it. Please help me in creating the application in ASP.NET. If you able to give me the whole code then please do it…
    Thanks in advance.

  18. Hey there.
    Can you explain me more the parts with the ASCIIEncoding / Stream / byte[] / Read / Write. I understand that these chunks of the code do the message sending/receiving itself, but I get it only as general overview and I need it line by line, so I can continue with writing code for my own purposes.
    Secondly – how can I make the server and the client to run and be able to exchange messages until I close the application, but not only for 1 single message.

    Thanks in advance.
    Cheers!

    1. Hello Ehtisham,

      Have you tried to use your external ip instead of the internal I used in the tutorial? I have made some tests and it seems to work ok over the internet.

      Regards,
      Felipe

      1. Thanks for answering Felipe..i also tried it and it work fine. Thanks for the great work..Regards..

  19. hello
    I am a beginner at programing , I need to make an
    application
    that takes operand from the client and do some calculations on the server and then return the results
    wher should I add the part of the program that does the calculation ?
    Regards,
    kadi

  20. Hi, can i send messages to remote computer which is on another network through internet using the example shown in the tutorial ?

  21. Hi Felipe,
    I have several questions related to this socket programming. I am new in Visual C# though. I created the client form based on Windows Application form and got confused to add the socket programming script. If you don’t mind, I’d like to add you on Skype.

    Regards,
    Thomhert

  22. hi fpgentil,
    ur code worked fine for me… i actually put the server code in an infinite whil me loop
    and after every message giving option to the client to conitnue the chat…
    could you please shed some more light on ASCII encoding and byte[] part…
    very helpful…
    thanks

    1. Hello Shamir,

      What kind of error do you have encountered?

      My email is: cdigentil at gmail
      Facebook: felipe.gentil
      Skype: gen7il

      Feel free to contact me 🙂

      Regards,
      Felipe

      1. Hello Shamir,

        Why can’t you open your socket? Is your application not being blocked by Win firewall? Show me what kind of error you’re receiving 🙂

        I’m sorry but I don’t have this code anymore :/

        Regards,
        Felipe

  23. Hello
    Felipe,

    I am Mishaal, I have just started working on C#.
    It is a Very nice and helpful tutorial, and from seeing this I think you can help me in my app, want to discuss it with you.can I have your email ?????

    1. Hello Mishaal 🙂

      Indeed you can have my email, it’s cdigentil at gmail.
      I’m not working with C# anymore, but I’ll be glad to help.

      Cheers,
      Felipe

  24. hi this is nice i i want if some one help me in this issue the issue is i want , a server when a client just connect server start automatic sending data every after two second . and want to see continiusly in client window . please help me in this regard

    1. Hello,

      What have you done so far? That doesn’t seem to be much different from this tutorial, check my other tutorial about async communication, maybe it fits better in your case.

      Cheers,
      Felipe

  25. I am a teacher from Malaysia(South East Asia),i would like to ask a permission to download your image(Client-Server Model) to be used in my teacher training class.Thank.

  26. Hello Sir,
    I am relatively new to C# and I am currently working on developing a C# program which can perform file transfer between client & server wherein the file transfer can be initiated by either client or server. Can u please help me out?

    1. Sure, I believe the principle is the same of transfering a simple data, you reconstruct your file on the other side.

      Have you tried this out?

      Cheers,
      Felipe

Leave a reply to Waleed Qayyum Cancel reply