01: package vicazh.hyperpool.stream.net.socks;
02:
03: import java.io.*;
04: import java.net.*;
05: import vicazh.hyperpool.stream.net.*;
06:
07: /**
08: * The switch
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class SwitchService extends Service implements
14: SwitchServiceMBean {
15: public SwitchService() {
16: }
17:
18: int timeout;
19:
20: int size;
21:
22: /**
23: * @param timeout
24: * socket timeout
25: * @param size
26: * packet size
27: */
28: public SwitchService(int timeout, int size) {
29: this .timeout = timeout;
30: this .size = size;
31: }
32:
33: public Connection getConnection() {
34: return new SwitchConnection(this );
35: }
36:
37: public OutputStream get(OutputStream outputstream)
38: throws IOException {
39: vicazh.hyperpool.stream.net.Socket socket = new Stream(null,
40: outputstream).getSocket();
41: if (socket.socket == null) {
42: OutService service = new UDPOutService(timeout, size);
43: Stream stream = ((UDPInService) socket.stream.connection.element).stream;
44: if (stream.getType() == 3)
45: service.setHost(new String(stream.getAddress()));
46: else
47: service.address = InetAddress.getByAddress(stream
48: .getAddress());
49: service.setPort(stream.getPort());
50: return service.get(outputstream);
51: } else
52: return super.get(outputstream);
53: }
54:
55: }
|