MSocket library

MSocket is a java socket library that is compatible with android and any JVM supporting machine.
It supports:

  1. Connection mobility: pre-lookup, connect time, individual and simultaneous mobility.
  2. Multi-homed & multipath communication.
  3. Mobile-to-Mobile communication: relaying behind NATs via proxies.

Examples

A demo server and client code is explained in the following tabs. For running the code necessary jars can be downloaded from the Resources section.
Set up gns account on the server.
    On command prompt        
         $ java -jar gns-cli-<VersionNum>.jar 
         On gns-cli console        
            > set_default_gns gnserve.net 24398 true       
            > gns_connect gnserve.net 24398 true        
            > account_create YourEmailAddress@example.com        
           Console will print "An email has been sent to YourEmailAddress@example.com with instructions on how to verify the new
           account." Check YourEmailAddress@example.com email account and verify the account. Then on the gns-cli cosole        
           > guid_use YourEmailAddress@example.com        
           > set_default_guid YourEmailAddress@example.com

Run the server sample code given below.
    Compile the serve code
         $ javac -cp msocket-<VersionNum>.jar MSocketServer.java
     Run the server
         $ java -cp msocket-<VersionNum>.jar:. MSocketServer testServer1

testServer1 above is the name of the server. This can be any name and it should be unique.


Sample server code


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import edu.umass.cs.msocket.MServerSocket;
import edu.umass.cs.msocket.MSocket;
import edu.umass.cs.msocket.mobility.MobilityManagerServer;

public class MSocketServer
{
             public static void main(String[] args) throws IOException
             {
                      String serverName = args[0];
                      MServerSocket mserv = new MServerSocket(serverName);
                     //while(true)
                      {
                                   MSocket msocket = mserv.accept();
                                   OutputStream outstream = msocket.getOutputStream();
                                   InputStream inpstream = msocket.getInputStream();
                                   byte[] byteArray = new byte[1000];
                                   int i=0;
                                   while(i<10)
                                   {
                                                 outstream.write( new String("hello world from server").getBytes() );
                                                 inpstream.read(byteArray);
                                                 System.out.println(new String(byteArray));
                                                 try {
                                                         Thread.sleep(2000);
                                                      }
                                                 catch (InterruptedException e)
                                                 {
                                                       e.printStackTrace();
                                                 }
                                                 i++;
                                   }
                                   msocket.close();
                      }
                      mserv.close();
                      MobilityManagerServer.shutdownMobilityManager();
             }
}
Set up gns information on the client.
      On the client msocket just needs gns hostname and portnumber, it doesn't need any account creation. Steps for these are       described below.
       
      On command prompt
              $ java -jar gns-cli-<VersionNum>.jar
              On gns-cli console
                     > set_default_gns gnserve.net 24398 true
                     > quit
            
      Start the client sample code given below.
      Compile the serve code
               $ javac -cp msocket-<VersionNum>.jar MSocketClient.java Run the server
               $ java -cp msocket-<VersionNum>.jar:. MSocketClient testServer1
      
       testServer1 is the name of the server to connect to. It should be same as given while starting the server.



import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import edu.umass.cs.msocket.MSocket;
import edu.umass.cs.msocket.mobility.MobilityManagerClient;
public class MSocketClient
{
               public static void main(String[] args) throws IOException
               {
                           String serverName = args[0];
                           MSocket msock = new MSocket(serverName, 0);
                           OutputStream outstream = msock.getOutputStream();
                           InputStream inpstream = msock.getInputStream();
                           byte[] byteArray = new byte[1000];
                           int i=0;
                           while(i < 10)
                           {
                                      outstream.write( new String("hello world from client").getBytes() );
                                      inpstream.read(byteArray);
                                      System.out.println(new String(byteArray));
                                      try {
                                             Thread.sleep(2000);
                                       } catch (InterruptedException e)
                                       {
                                               e.printStackTrace();
                                       }
                                       i++;
                            }
                           msock.close();
                           MobilityManagerClient.shutdownMobilityManager();
               }
}

Resources

Publications

About

MSocket and GNS, which MSocket uses internally, is developed at College of Information and computer science at UMass Amherst in Prof. Arun Venkataramani's group with following people contributing to the initial code development.

Prof. Arun Venkataramani
UMass Amherst
Abhigyan Sharma
UMass Amherst
David Westbrook
UMass Amherst
Aditya Yadav
UMass Amherst