-
Notifications
You must be signed in to change notification settings - Fork 4
Simple desktop example
Prerequisites: JDK1.8+, bash
Steps:
-
Download the latest
msocket-1.0.0.jar
from here. -
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.
-
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
. -
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. -
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. -
Both the server and the client applications exchange hello word messages 10 times and then close their respective sockets. On completion, the
TestMSocketServer
printsServer application complete
andTestMSocketClient
printsClient application complete
. -
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.