How to make client server
-
Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace
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
-
Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace
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
-
Hi Guys , how can i make client server in C# can any one provide me the code for example, thankx in advnace
...or the easist way if it's sufficient for your purposes is ASP.NET webservices.
Regards, Rob Philpott.
-
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
-
...or the easist way if it's sufficient for your purposes is ASP.NET webservices.
Regards, Rob Philpott.
-
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 helpsDo your best to be the best
-
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 helpsDo your best to be the best
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.
-
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.
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