package handlers.link;
import handlers.AbstractServerHandler;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import common.ClientServerProtocol;
import connection.ClientConnection;
import static main.ServerMain.*;
public class GetAddressHandler extends AbstractServerHandler
{
public void execute(ClientConnection connection, ObjectInputStream is,
ObjectOutputStream os) throws IOException, ClassNotFoundException
{
int clientId = is.readInt();
ClientConnection client = getConnectionManager().getClientById(clientId);
if (client == null)
{
throw new IOException();
}
os.write(ClientServerProtocol.PROTOCOL_LINK);
os.write(ClientServerProtocol.Link.OP_ADDRESS);
os.writeInt(clientId);
os.writeObject(new InetSocketAddress(client.getAddress(), client.getPort()));
}
}