0

Hello,

I am trying to create an IRC server. The thing is that I dont want this server to run on "localhost", I want to connect this server to other upstream IRC servers. I dont know how to do that. I.E. I want this server to connect to smth.hostname.com on port 9997 and get information from it. Please help!!!

public class Server {

public static void main(String[] arg) {
		new Server(60656);
	}

	private ServerSocket serverSocket;
	
	Server(int port) {
		
		try 
		{
			serverSocket = new ServerSocket(port);
			
			System.out.println("Server waiting for client on port " + serverSocket.getLocalPort());
			
			while(true) 
			{
				Socket socket = serverSocket.accept(); 
				System.out.println("New client asked for a connection");
				
				TcpThread t = new TcpThread(socket);    // make a thread of it
				System.out.println("Starting a thread for a new Client");
				
				t.start();
			}
		}
		catch (IOException e) {
			System.out.println("Exception on new ServerSocket: " + e);
		}
	}		


	
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by ~s.o.s~
0

AFAIK, you can't do that(*binding* to a port on an arbitrary host) for obvious reasons. A solution would be to bind to a port on your local host and delegate all requests to the other hosts by opening a normal Socket connection to it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.