01: package vicazh.hyperpool.stream.net;
02:
03: import java.io.*;
04: import java.net.*;
05: import vicazh.hyperpool.stream.*;
06:
07: class UDPOutConnection extends Connection {
08: UDPOutConnection(Element element) {
09: super (element);
10: }
11:
12: DatagramSocket socket;
13:
14: public void setClient(OutputStream outputstream) throws IOException {
15: socket = new DatagramSocket();
16: socket.setSoTimeout(((OutService) element).timeout);
17: setClient(new UDPOutStream(this , InetAddress
18: .getByName(((OutService) element).getHost())));
19: new Thread() {
20: public void run() {
21: try {
22: while (!socket.isClosed()) {
23: byte[] buf = new byte[((UDPOutService) element).size];
24: DatagramPacket packet = new DatagramPacket(buf,
25: buf.length);
26: socket.receive(packet);
27: Transfer.run(packet, getServer());
28: }
29: } catch (Exception e) {
30: try {
31: socket.close();
32: } catch (Exception ex) {
33: }
34: }
35: try {
36: getServer().close();
37: } catch (Exception e) {
38: }
39: }
40: }.start();
41: }
42:
43: public void close() {
44: try {
45: socket.close();
46: } catch (Exception e) {
47: }
48: super.close();
49: }
50: }
|