-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandshakeMessage.java
42 lines (30 loc) · 981 Bytes
/
HandshakeMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.kd.chat.messaging;
import java.io.UnsupportedEncodingException;
public class HandshakeMessage extends AbstractMessage{
public static final String PROTOCOL_STRING = "Super Chat Master";
protected final String username;
protected final int listenPort;
public int getListenPort(){
return this.listenPort;
}
public HandshakeMessage(final String username, final int listenPort)
throws UnsupportedEncodingException {
super(3+HandshakeMessage.PROTOCOL_STRING.getBytes("UTF-16BE").
length + username.getBytes("UTF-16BE").length,
AbstractMessage.TYPE_HANDSHAKE_MESSAGE);
this.username = username;
this.listenPort = listenPort;
}
public String getUsername(){
return this.username;
}
@Override
public String toString(){
StringBuffer sb = new StringBuffer();
sb.append(super.toString()).append(',').
append(PROTOCOL_STRING).append(',').
append(this.username).append(',').
append(this.listenPort);
return sb.toString();
}
}