/** * Creates an instance of {@link NioServer} that opens a server channel and listens for connections. * Needs to be started next. * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param port The local port to bind to * @throws Exception Thrown if the creation failed */ public NioServer(InetAddress bind_addr, int port) throws Exception { this(new DefaultThreadFactory("nio", false), new DefaultSocketFactory(), bind_addr, port, port+50, null, 0); }
/** * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections. * The end port defaults to (port + 50). Needs to be started next. * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param port The local port to bind to. If 0, the port will be picked by the OS. * @throws Exception Thrown if the creation failed */ public TcpServer(InetAddress bind_addr, int port) throws Exception { this(new DefaultThreadFactory("tcp", false), new DefaultSocketFactory(), bind_addr, port, port+50, null, 0); }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); destination=new IpAddress(remote.getAddress(), remote.getPort()); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
public void init() throws Exception { super.init(); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "srv-sock", bind_addr, bind_port, bind_port+50); acceptor=new Acceptor(bind_addr, bind_port); }
/** * Creates an instance of an {@link NioClient} that acts as a <em>client</em>: no server channel is created and * no acceptor is started to listen for incoming connections. Instead, a channel is created * (bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the * remote server and receive messages from it. Note that there is only a single TCP connection established between * the client and server. * @param bind_addr The address to which the local channel should bind to. Can be null, then the OS picks the address * @param bind_port The local port. Can be 0, then the OS picks the port. * @param server_addr The address of the server to connect to * @param server_port The port of the server to connect to. * @throws Exception If the creation failed */ public NioClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) { this(new DefaultThreadFactory("nio", false), new DefaultSocketFactory()); clientBindAddress(bind_addr).clientBindPort(bind_port); this.remote_addr=new IpAddress(server_addr, server_port); }
/** * Creates an instance of an {@link TcpClient} that acts as a <em>client</em>: no server socket is created and * no acceptor is started to listen for incoming connections. Instead, a client socket is created * (bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the * remote server and receive messages from it. Note that there is only a single TCP connection established between * the client and server. * @param bind_addr The address to which the local socket should bind to. Can be null, then the OS picks the address * @param bind_port The local port. Can be 0, then the OS picks the port. * @param server_addr The address of the server to connect to * @param server_port The port of the server to connect to. * @throws Exception If the creation failed */ public TcpClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) { this(new DefaultThreadFactory("tcp", false), new DefaultSocketFactory()); clientBindAddress(bind_addr).clientBindPort(bind_port); this.remote_addr=new IpAddress(server_addr, server_port); }
/** * Creates an instance of {@link NioServer} that opens a server channel and listens for connections. * Needs to be started next. * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param port The local port to bind to * @throws Exception Thrown if the creation failed */ public NioServer(InetAddress bind_addr, int port) throws Exception { this(new DefaultThreadFactory("nio", false), new DefaultSocketFactory(), bind_addr, port, port+50, null, 0); }
/** * Creates an instance of {@link TcpServer} that creates a server socket and listens for connections. * The end port defaults to (port + 50). Needs to be started next. * @param bind_addr The local address to bind to. If null, the address will be picked by the OS * @param port The local port to bind to. If 0, the port will be picked by the OS. * @throws Exception Thrown if the creation failed */ public TcpServer(InetAddress bind_addr, int port) throws Exception { this(new DefaultThreadFactory("tcp", false), new DefaultSocketFactory(), bind_addr, port, port+50, null, 0); }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception { local=new InetSocketAddress(local_addr, local_port); remote=new InetSocketAddress(remote_addr, remote_port); destination=new IpAddress(remote.getAddress(), remote.getPort()); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort()); System.out.println("Listening on " + srv_sock.getLocalSocketAddress()); acceptor=new Acceptor(); acceptor.start(); sock=new Socket(); //sock.bind(local); sock.setSendBufferSize(SOCK_SEND_BUF_SIZE); sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE); try { sock.connect(remote); output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); System.out.println("Connected to " + sock.getRemoteSocketAddress()); } catch(Throwable t) { System.out.println("Failed connecting to " + remote + ": will only act as server"); } }
public void init() throws Exception { super.init(); srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "srv-sock", bind_addr, bind_port, bind_port+50); acceptor=new Acceptor(bind_addr, bind_port); }
/** * Creates an instance of an {@link NioClient} that acts as a <em>client</em>: no server channel is created and * no acceptor is started to listen for incoming connections. Instead, a channel is created * (bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the * remote server and receive messages from it. Note that there is only a single TCP connection established between * the client and server. * @param bind_addr The address to which the local channel should bind to. Can be null, then the OS picks the address * @param bind_port The local port. Can be 0, then the OS picks the port. * @param server_addr The address of the server to connect to * @param server_port The port of the server to connect to. * @throws Exception If the creation failed */ public NioClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) { this(new DefaultThreadFactory("nio", false), new DefaultSocketFactory()); clientBindAddress(bind_addr).clientBindPort(bind_port); this.remote_addr=new IpAddress(server_addr, server_port); }
/** * Creates an instance of an {@link TcpClient} that acts as a <em>client</em>: no server socket is created and * no acceptor is started to listen for incoming connections. Instead, a client socket is created * (bound to bind_addr/bind_port) and connected to server_addr/server_port. This is used to send messages to the * remote server and receive messages from it. Note that there is only a single TCP connection established between * the client and server. * @param bind_addr The address to which the local socket should bind to. Can be null, then the OS picks the address * @param bind_port The local port. Can be 0, then the OS picks the port. * @param server_addr The address of the server to connect to * @param server_port The port of the server to connect to. * @throws Exception If the creation failed */ public TcpClient(InetAddress bind_addr, int bind_port, InetAddress server_addr, int server_port) { this(new DefaultThreadFactory("tcp", false), new DefaultSocketFactory()); clientBindAddress(bind_addr).clientBindPort(bind_port); this.remote_addr=new IpAddress(server_addr, server_port); }