-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentSocketImplFactory.java
executable file
·36 lines (31 loc) · 1.14 KB
/
StudentSocketImplFactory.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
import java.net.*;
//---------------------------------------------------
//
// class StudentSocketImplFactory
//
// this object is what actually creates each INSTANCE of a
// SocketImpl object. In TCPStart.main(), we call
//
// Socket.setSocketImplFactory( new StudentSocketImplFactory(D) );
//
// (this is a static function)
// so, when we create a java Socket, it will make a call to
// createSocketImpl(), and the Socket will use OUR code!!!
//
//---------------------------------------------------
class StudentSocketImplFactory implements SocketImplFactory {
// the Demultiplexer has to be known to every SocketImpl, so that it
// can communicate with it
private Demultiplexer D;
public StudentSocketImplFactory(Demultiplexer D) {
super();
this.D = D;
}
// Socket object makes this call to get one instance of SocketImpl.
// reminder: each socket will get a DIFFERENT instance of
// SocketImpl. this is GOOD, so that we will have one TCPConnection
// for each Socket!!
public SocketImpl createSocketImpl() {
return ( new StudentSocketImpl(D) );
}
}