954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

IRC server

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


	
}
scrape
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: