Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public void connect(InetAddress remoteAddress, int remotePort) throws IOException, SocketTimeoutException {
  2. try {
  3. if(remoteAddress != null) {
  4. this.remoteAddress = remoteAddress.getHostAddress();
  5. this.remotePort = remotePort;
  6. }
  7.  
  8. KtnDatagram SYN = constructPacket(KtnDatagram.SYN, "lol");
  9. KtnDatagram SYN_ACK = sendPacket(SYN);
  10. this.state = SYN_SENT;
  11.  
  12. if(SYN_ACK != null) {
  13. this.state = ESTABLISHED;
  14. this.sendAck(SYN_ACK, KtnDatagram.ACK);
  15. this.remoteAddress = SYN_ACK.getSrc_addr();
  16. this.remotePort = SYN_ACK.getSrc_port();
  17. }
  18. else {
  19. throw new Exception();
  20. }
  21. }
  22. catch(Exception e) {
  23. e.printStackTrace();
  24. e.toString();
  25. }
  26. }
Add Comment
Please, Sign In to add comment