Umm...shouldn't that be 4000? Servers are generally created on a fixed port. Thats why they are called servers...
Ah, I had tried this earlier, and had made a check, with netstat -a, command to find out whether this was available. But, then, it did not create a server.
Tried, this today again, and now it does, create a server on port 4000, but still takes around 7-8 minutes.
Umm...isn't that kinda obvious. If you start it at port 0, it will take a long time to determine a free port.
The reason, I used port 0 is because, I could get the server started on 4000 and Redhat did not make it visible to me whether it had bound some application to that port. Port 0 ultimately, gave a choice to the OS to find out port for me :)
And eewwww...you should've mentioned that you're doing this in Java...
I thought, Java was preferred for networking programming and assumed, this would be true atleast for the years to come by. Is it true?
I dont think you need to do it in Java but you never mentioned which language you were using. So I assumed C.
Ah, for the moment, I don't think, I would be doing it in C, atleast till I am sure, I can do it.
Anyway, try googling the next time. This is the right way to build a client / server:
I do google, a lot more, but solutions seem to be passive, which does seem to help all the time. At these times, I post to the list!
__________________________________________________________ Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com
On Sat, Apr 29, 2006 at 08:09:34AM +0100, Roshan wrote:
Ah, for the moment, I don't think, I would be doing it in C, atleast till I am sure, I can do it.
How do you know you can do it if you don't try doing it?
On Saturday 29 April 2006 07:09, Roshan wrote:
Tried, this today again, and now it does, create a server on port 4000, but still takes around 7-8 minutes.
you must've screwed up your system...
I thought, Java was preferred for networking programming and assumed, this would be true atleast for the years to come by. Is it true?
Dunno. I hate Java. I wouldn't use it if my life depended on it :/
Ah, for the moment, I don't think, I would be doing it in C, atleast till I am sure, I can do it.
hehehe :)
I do google, a lot more, but solutions seem to be passive, which does seem to help all the time. At these times, I post to the list!
right ;)
The code below works perfectly for me. I have shamelessly copied it from some website whose address I dont remember. I modified it a bit for our needs ofcourse. I have built it using gcj and java on my FC2 system and it works perfectly. It has no issues binding to port 4000.
import java.io.*; import java.net.*;
public class echoServer { public static void main(String args[]) {
ServerSocket echoServer = null; String line; DataInputStream is; PrintStream os; Socket clientSocket = null;
try { echoServer = new ServerSocket(4000); } catch (IOException e) { System.out.println(e); }
try { clientSocket = echoServer.accept(); is = new DataInputStream(clientSocket.getInputStream()); os = new PrintStream(clientSocket.getOutputStream());
while (true) { line = is.readLine(); System.out.println("Client: " + line); os.println("Server: " + line); } } catch (IOException e) { System.out.println(e); } } }
On Sat, Apr 29, 2006 at 08:09:34AM +0100, Roshan wrote:
Tried, this today again, and now it does, create a server on port 4000, but still takes around 7-8 minutes.
Umm...isn't that kinda obvious. If you start it at port 0, it will take a long time to determine a free port.
The reason, I used port 0 is because, I could get the server started on 4000 and Redhat did not make it visible to me whether it had bound some application to that port. Port 0 ultimately, gave a choice to the OS to find out port for me :)
I'm guessing that the kernel (or JVM maybe!) is trying to *find* a free port for you startting from the lower end of 65536(?) that is why it is taking so long. Why not simply try listening on port 4000 and exit if the socket creation fails or maybe try the next one until you find a free one _within_ a reasonable time limit and fail completely if not.
Nosferatu