Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Comms {
- private Socket socket;
- private InputStream in;
- private OutputStream out;
- private ObjectInputStream oIn;
- private ObjectOutputStream oOut;
- public Comms(Socket socket) {
- this.socket = socket;
- }
- public Socket getSocket() {
- return socket;
- }
- public void setSocket(Socket socket) {
- this.socket = socket;
- }
- public Object recieveMessage() throws IOException, ClassNotFoundException {
- Object recieved;
- in = socket.getInputStream();
- oIn = new ObjectInputStream(in);
- while ((recieved = oIn.readObject()) != null) {
- return recieved;
- }
- return null;
- }
- public void sendMessage(Object input) throws IOException {
- out = socket.getOutputStream();
- oOut = new ObjectOutputStream(out);
- oOut.writeObject(input);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement