Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this in the following way.</p> <p><strong>step 1</strong> : you have to create a Listener. <strong>TcpListener</strong> class or <strong>HttpListener</strong> in .net can be used to develop the listener. This code shows how to implement a TCP listener.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Net; using System.Threading; //Author : Kanishka namespace ServerSocketApp { class Server { private TcpListener tcpListn = null; private Thread listenThread = null; private bool isServerListening = false; public Server() { tcpListn = new TcpListener(IPAddress.Any,8090); listenThread = new Thread(new ThreadStart(listeningToclients)); this.isServerListening = true; listenThread.Start(); } //listener private void listeningToclients() { tcpListn.Start(); Console.WriteLine("Server started!"); Console.WriteLine("Waiting for clients..."); while (this.isServerListening) { TcpClient tcpClient = tcpListn.AcceptTcpClient(); Thread clientThread = new Thread(new ParameterizedThreadStart(handleClient)); clientThread.Start(tcpClient); } } //client handler private void handleClient(object clientObj) { TcpClient client = (TcpClient)clientObj; Console.WriteLine("Client connected!"); NetworkStream stream = client.GetStream(); ASCIIEncoding asciiEnco = new ASCIIEncoding(); //read data from client byte[] byteBuffIn = new byte[client.ReceiveBufferSize]; int length = stream.Read(byteBuffIn, 0, client.ReceiveBufferSize); StringBuilder clientMessage = new StringBuilder(""); clientMessage.Append(asciiEnco.GetString(byteBuffIn)); //write data to client //byte[] byteBuffOut = asciiEnco.GetBytes("Hello client! \n"+"You said : " + clientMessage.ToString() +"\n Your ID : " + new Random().Next()); //stream.Write(byteBuffOut, 0, byteBuffOut.Length); //writing data to the client is not required in this case stream.Flush(); stream.Close(); client.Close(); //close the client } public void stopServer() { this.isServerListening = false; Console.WriteLine("Server stoped!"); } } } </code></pre> <p><strong>Step 2</strong> : you can pass parameters to the created server as a GET request. You can use either JavaScript or HTML Forms to pass parameters. JavaScript libraries like jQuery and Dojo will make it easier to make ajax requests.</p> <pre><code>http://localhost:8090?id=1133 </code></pre> <p>You have to modify the above code to retrieve the parameters send as a GET request. I recommend to use <strong>HttpListener</strong> instead of <strong>TcpListener</strong></p> <p>Once you have done with the listening part rest part is just processing the retrieved parameters from the request.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload