-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeverIntArray.java
More file actions
41 lines (26 loc) · 1.07 KB
/
SeverIntArray.java
File metadata and controls
41 lines (26 loc) · 1.07 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
import java.io.*;
import java.net.*;
public class ServerIntArray{
public static void main(String[] args) {
int port=3000;
try {
System.out.println("Debug; waiting for connect");
ServerSocket ss = new ServerSocket(port); // possible exception
while(true) {
Socket s = ss.accept(); // blocks until connection made by client
System.out.println("Debug: made connection");
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
Object message = ois.readObject(); // exception could happen here
System.out.println(message.toString());
System.out.println("Debug: Recieved");
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
int sum = 1;
oos.writeObject(sum);
System.out.println("Debug: Sent");
}
} catch (Exception e) {
System.out.println("Something went wrong!");
e.printStackTrace();
}
}
}