-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPStart.java
executable file
·78 lines (56 loc) · 2.1 KB
/
TCPStart.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.net.*;
//---------------------------------------------------
//
// class TCPStart
//
// this is the hub of the entire socket implementation.
// all modules are initialized here.
//
//
// code that runs on TOP of this whole implementation will
// be put in this file, as separate threads.
//
// to start our implementation of TCP, type
// java TCPStart <UDP port #>
//
//
//---------------------------------------------------
class TCPStart {
public final static String PORTRESOURCE = "UDPPORT";
public final static String LOSSRATERESOURCE = "LOSSRATE";
static public void start() {
// check command line args
if (System.getProperty(PORTRESOURCE)==null) {
System.err.println("Must set "+PORTRESOURCE+" for UDP port to use with "+
"-D"+PORTRESOURCE+"=<num>");
System.exit(1);
}
// this number will initialize what port # you want your UDP
// wrapper to run on.
int portForUDP = Integer.parseInt(System.getProperty(PORTRESOURCE));
// initialize TCPWrapper's port number for UDP wrapping
TCPWrapper.setUDPPortNumber( portForUDP );
// initialize more TCPWrapper stuff here, if you want to test packet
// dropping, or if you want to change the sending-rate limit
// create an instance of the Demultiplexer
Demultiplexer D = new Demultiplexer( portForUDP );
// create an instance of OUR SocketImplFactory
StudentSocketImplFactory myFactory = new StudentSocketImplFactory(D);
// tell all Socket objects of this program to use OUR
// implementation of SockImpl
try {
Socket.setSocketImplFactory( myFactory );
ServerSocket.setSocketFactory( myFactory );
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
// start the demultiplexer
D.start();
if (System.getProperty(LOSSRATERESOURCE)!=null) {
TCPWrapper.dropRandomPackets
(System.currentTimeMillis(),
Double.parseDouble(System.getProperty(LOSSRATERESOURCE)));
}
}
}