1
1
package au .edu .unimelb .tcp .client ;
2
2
3
+ import org .json .simple .JSONArray ;
4
+ import org .json .simple .JSONObject ;
5
+ import org .json .simple .parser .JSONParser ;
6
+ import org .json .simple .parser .ParseException ;
7
+
8
+ import javax .net .ssl .SSLSocket ;
9
+ import javax .net .ssl .SSLSocketFactory ;
3
10
import java .io .BufferedReader ;
4
11
import java .io .DataOutputStream ;
5
12
import java .io .IOException ;
6
13
import java .io .InputStreamReader ;
7
- import java .net .Socket ;
8
14
import java .util .HashSet ;
9
15
10
- import org .json .simple .JSONArray ;
11
- import org .json .simple .JSONObject ;
12
- import org .json .simple .parser .JSONParser ;
13
- import org .json .simple .parser .ParseException ;
14
-
15
16
public class MessageReceiveThread implements Runnable {
16
17
17
- private Socket socket ;
18
+ private SSLSocket socket ;
18
19
private State state ;
19
20
private boolean debug ;
20
21
private Client client ;
@@ -27,7 +28,7 @@ public class MessageReceiveThread implements Runnable {
27
28
28
29
private MessageSendThread messageSendThread ;
29
30
30
- public MessageReceiveThread (Socket socket , State state , MessageSendThread messageSendThread , Client client , boolean debug ) throws IOException {
31
+ public MessageReceiveThread (SSLSocket socket , State state , MessageSendThread messageSendThread , Client client , boolean debug ) throws IOException {
31
32
this .socket = socket ;
32
33
this .state = state ;
33
34
this .messageSendThread = messageSendThread ;
@@ -63,7 +64,7 @@ public void run() {
63
64
64
65
}
65
66
66
- public void MessageReceive (Socket socket , JSONObject message )
67
+ public void MessageReceive (SSLSocket socket , JSONObject message )
67
68
throws IOException , ParseException {
68
69
String type = (String ) message .get ("type" );
69
70
@@ -250,8 +251,9 @@ public void MessageReceive(Socket socket, JSONObject message)
250
251
System .out .println ("Connecting to server " + host + ":" + port );
251
252
System .out .print ("[" + state .getRoomId () + "] " + state .getIdentity () + "> " );
252
253
}
253
-
254
- Socket temp_socket = new Socket (host , port );
254
+
255
+ SSLSocketFactory sslsocketfactory = (SSLSocketFactory ) SSLSocketFactory .getDefault ();
256
+ SSLSocket temp_socket = (SSLSocket ) sslsocketfactory .createSocket (host , port );
255
257
256
258
// send #movejoin
257
259
DataOutputStream out = new DataOutputStream (temp_socket .getOutputStream ());
@@ -296,7 +298,7 @@ public void MessageReceive(Socket socket, JSONObject message)
296
298
}
297
299
}
298
300
299
- public void switchServer (Socket temp_socket , BufferedReader temp_in ) throws IOException {
301
+ public void switchServer (SSLSocket temp_socket , BufferedReader temp_in ) throws IOException {
300
302
in .close ();
301
303
in = temp_in ;
302
304
socket .close ();
0 commit comments