1 package org.sapia.ubik.net.udp; 2 3 import org.sapia.ubik.net.Connection; 4 import org.sapia.ubik.net.ConnectionFactory; 5 6 import java.io.IOException ; 7 8 import java.net.DatagramPacket ; 9 import java.net.DatagramSocket ; 10 import java.net.InetAddress ; 11 12 13 17 public class UDPConnectionFactory implements ConnectionFactory { 18 private int _bufSize; 19 private int _timeout; 20 21 24 public UDPConnectionFactory(int bufSize, int timeout) { 25 _bufSize = bufSize; 26 _timeout = timeout; 27 } 28 29 32 public Connection newConnection(String host, int port) 33 throws IOException { 34 return new UDPConnection(new UDPServerAddress(InetAddress.getByName(host), 35 port), _bufSize, _timeout); 36 } 37 38 public UDPConnection newConnection(InetAddress addr, int port) 39 throws IOException { 40 return new UDPConnection(new UDPServerAddress(addr, port), _bufSize, 41 _timeout); 42 } 43 44 public UDPConnection newConnection(DatagramSocket localSocket, 45 DatagramPacket pack) throws IOException { 46 return new UDPConnection(localSocket, pack, _bufSize, _timeout); 47 } 48 } 49 | Popular Tags |