/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package miu.libs.jbascf.demos.basic;

import miu.libs.jbascf.Communicator;
import miu.libs.jbascf.CommunicatorCallback;
import java.io.IOException;

/**
 *
 * @author Ndadji Maxime
 */
public class Server implements CommunicatorCallback{
    private Communicator communicator;
    
    public Server() {
        try {
            communicator = new Communicator(this, 1001);
        } catch (IOException ex) {
            System.out.println("Communication impossible");
        }
    }
    
    @Override
    public synchronized void clientMessageReceived(int comId, String message) {
        
    }

    @Override
    public synchronized void serverMessageReceived(int comId, String message) {
        try {
            System.out.println(message);
            communicator.sendMessage(comId, "Reponse du serveur");
        } catch (IOException ex) {
            
        }
    }

    @Override
    public synchronized void newConnectionToServer(int id) {
        try {
            System.out.println("Nouveau client");
            communicator.sendMessage(id, "Bienvenue du serveur");
        } catch (IOException ex) {
            
        }
    }
    
    public static void main(String [] args){
        new Server();
    }
}
