Show NetworkClient.java syntax highlighted
package persister.network;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import persister.Message;
import persister.distributed.ClientCommunicator;
/**
* */
public class NetworkClient {
private ObjectInputStream inputStream;
private ObjectOutputStream outputStream;
private ClientCommunicator communicator;
@SuppressWarnings("unused")
private CallbackThread callback;
public NetworkClient( String url, int port, ClientCommunicator communicator) throws IOException{
this.communicator = communicator;
InetAddress addr = InetAddress.getByName(url);
Socket socket = new Socket(addr, port);
outputStream = new ObjectOutputStream(socket.getOutputStream());
outputStream.flush();
inputStream = new ObjectInputStream(socket.getInputStream());
this.callback = new CallbackThread(inputStream, this.communicator);
}
public void send(Message msg) throws IOException {
outputStream.writeObject(msg);
}
}
See more files for this project here