Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.io.IOException;
  3. import java.net.*;
  4.  
  5. public class ClientPeer {
  6. private String sender_name;
  7. private Socket socket;
  8.  
  9. public ClientPeer(String name, Socket sk) throws IOException {
  10. this.sender_name = name;
  11. this.socket = sk;
  12.  
  13. }
  14.  
  15. public void sendMessage(String message) throws IOException {
  16.  
  17. Message m1 = new Message(sender_name, message);
  18. try{
  19. ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
  20. out.writeObject(m1);
  21.  
  22. }catch(IOException e){
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. public void close() throws IOException {
  28. try {
  29. socket.getOutputStream().close();
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement