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);
		}
	}		


	
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.