-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionProxy.java
More file actions
71 lines (60 loc) · 1.3 KB
/
ConnectionProxy.java
File metadata and controls
71 lines (60 loc) · 1.3 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
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
package ac.il.Shenkar;
import java.net.*;
import java.io.*;
public class ConnectionProxy extends Thread implements StringProducer,StringConsumer{
private Socket socket;
private InputStream is=null;
private OutputStream os=null;
private DataInputStream dis=null;
private DataOutputStream dos=null;
private StringConsumer consumer=null;
private StringProducer producer=null;
ConnectionProxy(Socket socket){
try{
this.socket=socket;
is=socket.getInputStream();
os=socket.getOutputStream();
dis=new DataInputStream(is);
dos=new DataOutputStream(os);
}
catch(IOException e){
//...
}
//--------------------//
}
@Override
public synchronized void consume(String str) {
try{
dos.writeUTF(str);
}
catch (IOException e){
System.out.println(e.getMessage());
}
}
@Override
public void addConsumer(StringConsumer sc) {
// TODO Auto-generated method stub
consumer=sc;
}
@Override
public void removeConsumer(StringConsumer sc) {
// TODO Auto-generated method stub
}
@Override
public void run(){
try{
while(true) {
String str=dis.readUTF();
consumer.consume(str);
}
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
@Override
public String infrom() {
// TODO Auto-generated method stub
return consumer.infrom();
}
}