-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRS.java
44 lines (39 loc) · 1 KB
/
SRS.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
43
44
package swselectiverepeat;
import java.io.*;
import java.net.*;
public class SRserver
{
static ServerSocket Serversocket;
static DataInputStream dis;
static DataOutputStream dos;
public static void main(String[] args) throws SocketException {
try {
int a[] = { 30, 40, 50, 60, 70, 80, 90, 100 };
Serversocket = new ServerSocket(8011);
System.out.println("Server Socket created!");
Socket client = Serversocket.accept();
dis = new DataInputStream(client.getInputStream());
dos = new DataOutputStream(client.getOutputStream());
System.out.println("The number of packets sent is:" + a.length);
int y = a.length;
dos.write(y);
dos.flush();
for (int i = 0; i < a.length; i++) {
dos.write(a[i]);
dos.flush();
}
int k = dis.read();
dos.write(a[k]);
dos.flush();
} catch (IOException e) {
System.out.println(e);
} finally {
try {
dis.close();
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}