-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOioServer.java
More file actions
45 lines (41 loc) · 1.08 KB
/
Copy pathOioServer.java
File metadata and controls
45 lines (41 loc) · 1.08 KB
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
43
44
45
package oioTest;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.Charset;
public class OioServer {
public static void main(String[] args) throws Exception {
OioServer os = new OioServer();
os.server(8888);
}
public void server(int port) throws Exception {
final ServerSocket socket = new ServerSocket(port);
try {
final Socket clientSocket = socket.accept();
System.out.println("Accept connection form " + clientSocket);
new Thread(new Runnable() {
@Override
public void run() {
OutputStream out;
try {
out = clientSocket.getOutputStream();
out.write("HI !!! \r\n".getBytes(Charset.forName("UTF-8")));
out.flush();
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
clientSocket.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}