// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
// 
//     private String type;
//     private Object message;
// 
//     public IncomingServerMessage(String type, Object message) {
//         this.type = type;
//         this.message = message;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public Object getMessage() {
//         return message;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
// 
//     private Payload<?> payload;
//     private String ip;
//     private int port;
// 
//     public RegisterMessage(Payload<?> payload, String ip, int port) {
//         this.payload = payload;
//         this.ip = ip;
//         this.port = port;
//     }
// 
//     public String getIp() {
//         return ip;
//     }
// 
//     public int getPort() {
//         return port;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
// 
//     public static final int NONE = 0;
//     public static final int START = 1;
//     public static final int END = 2;
// 
//     private Payload<?> payload;
//     private int signal;
// 
// 
//     public SessionMessage(Payload<?> payload) {
//         this.payload = payload;
//         this.signal = NONE;
//     }
// 
//     public SessionMessage(Payload<?> payload, int signal) {
//         this.payload = payload;
//         this.signal = signal;
//     }
// 
//     public int getSignal() {
//         return signal;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
// 
//     public static final String REGISTER = "register";
//     public static final String SESSION = "session";
// 
// }


import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;




/**
 * Created by JoKr on 8/28/2016.
 */
class ServerSocketThread implements Runnable {

    private ServiceCallback callback;
    private Socket socket;

    public ServerSocketThread(ServiceCallback callback) {
        this.callback = callback;
    }

    @Override
    public void run() {
        try {
            Log.d("USER", "starting ServerSocket...");
            final ServerSocket serverSocket = new ServerSocket(0);
            notifySocketInitialized(serverSocket.getLocalPort());

            while (true) {
                socket = serverSocket.accept();
                Log.d("USER", "ServerSocket :: got incomingMessage");
                ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
// 
//     private String type;
//     private Object message;
// 
//     public IncomingServerMessage(String type, Object message) {
//         this.type = type;
//         this.message = message;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public Object getMessage() {
//         return message;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
// 
//     private Payload<?> payload;
//     private String ip;
//     private int port;
// 
//     public RegisterMessage(Payload<?> payload, String ip, int port) {
//         this.payload = payload;
//         this.ip = ip;
//         this.port = port;
//     }
// 
//     public String getIp() {
//         return ip;
//     }
// 
//     public int getPort() {
//         return port;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
// 
//     public static final int NONE = 0;
//     public static final int START = 1;
//     public static final int END = 2;
// 
//     private Payload<?> payload;
//     private int signal;
// 
// 
//     public SessionMessage(Payload<?> payload) {
//         this.payload = payload;
//         this.signal = NONE;
//     }
// 
//     public SessionMessage(Payload<?> payload, int signal) {
//         this.payload = payload;
//         this.signal = signal;
//     }
// 
//     public int getSignal() {
//         return signal;
//     }
// 
//     public Payload<?> getPayload() {
//         return payload;
//     }
// }
// 
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
// 
//     public static final String REGISTER = "register";
//     public static final String SESSION = "session";
// 
// }


// Path: localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;

package dev.jokr.localnet;




/**
 * Created by JoKr on 8/28/2016.
 */
class ServerSocketThread implements Runnable {

    private ServiceCallback callback;
    private Socket socket;

    public ServerSocketThread(ServiceCallback callback) {
        this.callback = callback;
    }

    @Override
    public void run() {
        try {
            Log.d("USER", "starting ServerSocket...");
            final ServerSocket serverSocket = new ServerSocket(0);
            notifySocketInitialized(serverSocket.getLocalPort());

            while (true) {
                socket = serverSocket.accept();
                Log.d("USER", "ServerSocket :: got incomingMessage");
                ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
                IncomingServerMessage message = (IncomingServerMessage) input.readObject();