-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocketThread.java
33 lines (33 loc) · 1.06 KB
/
socketThread.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
package Lab2;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class socketThread implements Runnable{
public socketThread(Socket s) {
}
public static void main(String[] args)
{
try{
ServerSocket ss = new ServerSocket(3999);
while(true){
Socket s = ss.accept();
socketThread st = new socketThread(s);
Thread mt = new Thread(st);
mt.start();
}
} catch(Exception e){
}
}
public void run(){
try{ServerSocket ss = new ServerSocket(3999);
Socket s = ss.accept();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
String data = dis.readUTF();
System.out.println("Read: "+data);
dos.writeUTF(data);
}catch(Exception e){
}
}
}