Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to make client server

How to make client server

Scheduled Pinned Locked Moved C#
tutorialcsharpsysadminquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    King Shez
    wrote on last edited by
    #1

    Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace

    S A R 3 Replies Last reply
    0
    • K King Shez

      Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace

      S Offline
      S Offline
      samtam
      wrote on last edited by
      #2

      There is more than one way to make client server applications in C#, u can go for .net remoting technology. u can easily find helping material on net. this article will help u www.c-sharpcorner.com/Network/RemotingInNETM.asp

      1 Reply Last reply
      0
      • K King Shez

        Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace

        A Offline
        A Offline
        Andrei Ungureanu
        wrote on last edited by
        #3

        Hi, Indeed there are several ways to create an client - server architecture in c#. It only depends on the type of data you want to transmit. If you want data over the Network then you should try using Socket (System.Net.Socket). If you need an example let me know.

        Do your best to be the best

        K 1 Reply Last reply
        0
        • K King Shez

          Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace

          R Offline
          R Offline
          Rob Philpott
          wrote on last edited by
          #4

          ...or the easist way if it's sufficient for your purposes is ASP.NET webservices.

          Regards, Rob Philpott.

          K 1 Reply Last reply
          0
          • A Andrei Ungureanu

            Hi, Indeed there are several ways to create an client - server architecture in c#. It only depends on the type of data you want to transmit. If you want data over the Network then you should try using Socket (System.Net.Socket). If you need an example let me know.

            Do your best to be the best

            K Offline
            K Offline
            King Shez
            wrote on last edited by
            #5

            OK Man provide me the example so i can work it out , thankx in advance

            A 1 Reply Last reply
            0
            • R Rob Philpott

              ...or the easist way if it's sufficient for your purposes is ASP.NET webservices.

              Regards, Rob Philpott.

              K Offline
              K Offline
              King Shez
              wrote on last edited by
              #6

              Well i don't want to use web services , iknow abt the web services , but i wanna make client Server with out web services, thanks in advance

              1 Reply Last reply
              0
              • K King Shez

                OK Man provide me the example so i can work it out , thankx in advance

                A Offline
                A Offline
                Andrei Ungureanu
                wrote on last edited by
                #7

                Well, It is very important to understand that sockets exchange only byte arrays between them, regardless of what the byte arrays contain (file, string message etc.). So it is very important that when you receive something to know what you receive. At first you should try to create your own communication protocol. In my example the client send a string message and the server receives it For the server: Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000>)); // 10000 is the port number Socket client = server.Accept(); // accepts a connection from a client byte []buffer = new byte[1024]; int read = 0; string receivedMessage = ""; while ( (read = client.Receive(buffer)) != 0 ) { receivedMessage = String.Concat(Encoding.ASCII.GetString(buffer),receivedMessage); if (read < buffer.Length) break; } client.Shutdown(SocketShutdown.Both); For the client: Socket client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); client.Connect(new IPEndPoint(Dns.Resolve("127.0.0.1").AddressList[0],10000)); string message = "This is a test"; client.Send(Encoding.ASCII.GetBytes(message)); client.Shutdown(SocketShutdown.Both); Hope it helps

                Do your best to be the best

                K 1 Reply Last reply
                0
                • A Andrei Ungureanu

                  Well, It is very important to understand that sockets exchange only byte arrays between them, regardless of what the byte arrays contain (file, string message etc.). So it is very important that when you receive something to know what you receive. At first you should try to create your own communication protocol. In my example the client send a string message and the server receives it For the server: Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000>)); // 10000 is the port number Socket client = server.Accept(); // accepts a connection from a client byte []buffer = new byte[1024]; int read = 0; string receivedMessage = ""; while ( (read = client.Receive(buffer)) != 0 ) { receivedMessage = String.Concat(Encoding.ASCII.GetString(buffer),receivedMessage); if (read < buffer.Length) break; } client.Shutdown(SocketShutdown.Both); For the client: Socket client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); client.Connect(new IPEndPoint(Dns.Resolve("127.0.0.1").AddressList[0],10000)); string message = "This is a test"; client.Send(Encoding.ASCII.GetBytes(message)); client.Shutdown(SocketShutdown.Both); Hope it helps

                  Do your best to be the best

                  K Offline
                  K Offline
                  King Shez
                  wrote on last edited by
                  #8

                  Thankx man for ur example when i am using this code snippet of the server it is giving the error on this m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000)) and shows no method of the tcp listener with the name of bind thers is the Server property of TCP Listener which have the method Bind , but its not workin plzzzzzzz, Reply me ASAP,thankx for ur reply.

                  A 1 Reply Last reply
                  0
                  • K King Shez

                    Thankx man for ur example when i am using this code snippet of the server it is giving the error on this m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000)) and shows no method of the tcp listener with the name of bind thers is the Server property of TCP Listener which have the method Bind , but its not workin plzzzzzzz, Reply me ASAP,thankx for ur reply.

                    A Offline
                    A Offline
                    Andrei Ungureanu
                    wrote on last edited by
                    #9

                    Hi, I must appologise. Please in the server code replace TCPListener with Socket. I confused the server declaration

                    Do your best to be the best

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups