Skip to content

Simple desktop example

ayadavumass edited this page Oct 11, 2016 · 12 revisions

Prerequisites: JDK1.8+, bash

Steps:

  1. Download the latest msocket-1.0.0.jar from here.

  2. A brief description of the sample server and client example is as follows. In the example a server, using MSocket, starts behind NAT and waits for clients to connect to it. The client in the example connects to the server, which is behind NAT, and both the server and the client exchange hello world messages 10 times and then close their respective sockets.

  3. To run the sample server and client example, open two terminal tabs and go inside the directory that contains the downloaded msocket-1.0.0.jar.

  4. In the first tab, start the server following these steps.

    Download the sample test server from Server.

    Compile TestMSocketServer.java

    javac -cp msocket-1.0.0.jar TestMSocketServer.java

    Run TestMSocketServer

    java -cp msocket-1.0.0.jar:. TestMSocketServer myTestServer

    myTestServer argument is the name of the server. This can be any name and it should be unique. On starting the server the following lines should be printed.

    Starting a server with name myTestServer

    Listening for incoming connections

    If there is a DUPLICATE_NAME_EXCEPTION then the provided name is already taken by someone else in GNS. Restart the server with a different name.

  5. In the second tab, start the client following these steps.

    Download the sample test client from [Client] (https://github.com/ayadavumass/Downloads/blob/master/SampleTestCode/TestMSocketClient.java).

    Compile TestMSocketClient.java

    javac -cp msocket-1.0.0.jar TestMSocketClient.java

    Run TestMSocketClient

    java -cp msocket-1.0.0.jar:. TestMSocketClient myTestServer

    myTestServer argument is the name of the server to connect to. The name of the server should be same as given in the step 4.

  6. Both the server and the client applications exchange hello word messages 10 times and then close their respective sockets. On completion, the TestMSocketServer prints Server application complete and TestMSocketClient prints Client application complete.

  7. The above steps run both the server and the client on the same machine, but the server and the client applications can be run on different machines using the same steps.

Clone this wiki locally