pellekrogholt

Untitled

Mar 29th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.     public class MessageHandler {
  2.        public static void sendMessage(Socket socket, String msg) {
  3.            try {
  4.                OutputStream os      = socket.getOutputStream();
  5.                DataOutputStream dos = new DataOutputStream( os );
  6.                dos.writeUTF(msg);
  7.                dos.flush();
  8.                System.out.println("Just sent message: " + msg);
  9.            } catch(Exception e) {
  10.                e.printStackTrace();
  11.            }
  12.        }
  13.  
  14.        public static String readMessage(Socket socket) {
  15.            try {
  16.                InputStream is      = socket.getInputStream();
  17.                DataInputStream ois = new DataInputStream( is );
  18.                String response     = ois.readUTF();
  19.                return response;
  20.            } catch(Exception e) {
  21.                e.printStackTrace();
  22.                return "FAILURE";
  23.            }
  24.        }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment