pellekrogholt

Untitled

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