// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
// 
//     private T payload;
// 
//     public Payload(T payload) {
//         this.payload = payload;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
// 
// }
// 
// 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;
//     }
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
     * Set receiver if you want to receive events from LocalSession and be notified about
     * new client connections.
     */
    public void setReceiver(OnUiEventReceiver receiver) {
        this.receiver = receiver;
    }

    private void sendSessionData(Class c, Bundle b) {
        Intent i = new Intent(context, ServerService.class);
        i.putExtra(ServerService.ACTION, ServerService.START_SESSION);
        i.putExtra(ServerService.CLASS, c);
        i.putExtra(ServerService.BUNDLE, b);
        context.startService(i);
    }

    private void registerMessageBroadcastReceiver() {
        BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(UI_EVENT);
        LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);

        BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
        IntentFilter intentFilter2 = new IntentFilter();
        intentFilter2.addAction(CONNECTED_CLIENT);
        LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
    }

    private class EventBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
// 
//     private T payload;
// 
//     public Payload(T payload) {
//         this.payload = payload;
//     }
// 
//     public T getPayload() {
//         return payload;
//     }
// 
// 
// }
// 
// 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/LocalServer.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;

     * Set receiver if you want to receive events from LocalSession and be notified about
     * new client connections.
     */
    public void setReceiver(OnUiEventReceiver receiver) {
        this.receiver = receiver;
    }

    private void sendSessionData(Class c, Bundle b) {
        Intent i = new Intent(context, ServerService.class);
        i.putExtra(ServerService.ACTION, ServerService.START_SESSION);
        i.putExtra(ServerService.CLASS, c);
        i.putExtra(ServerService.BUNDLE, b);
        context.startService(i);
    }

    private void registerMessageBroadcastReceiver() {
        BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(UI_EVENT);
        LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);

        BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
        IntentFilter intentFilter2 = new IntentFilter();
        intentFilter2.addAction(CONNECTED_CLIENT);
        LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
    }

    private class EventBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            SessionMessage message = (SessionMessage) intent.getExtras().getSerializable(SessionMessage.class.getName());