Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MessageHandler {
- public static void sendMessage(Socket socket, String msg) {
- try {
- OutputStream os = socket.getOutputStream();
- DataOutputStream dos = new DataOutputStream( os );
- dos.writeUTF(msg);
- dos.flush();
- System.out.println("Just sent message: " + msg);
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public static String readMessage(Socket socket) {
- try {
- InputStream is = socket.getInputStream();
- DataInputStream ois = new DataInputStream( is );
- String response = ois.readUTF();
- return response;
- } catch(Exception e) {
- e.printStackTrace();
- return "FAILURE";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment