QUOTE(Gloin @ 16 Aug, 2008 - 09:20 AM)

When you work with sockets, you can use different transport protocols among which TCP and UDP are the most common types. I'm sure you've heard of TCP, especially in the context TCP/IP. Basically, TCP is a reliable connection where a number of built in methods will help making sure your data is delivered, however TCP requires that you follow a certain protocol. UDP instead is an unreliable, best-effort service that doesn't care what happens to your data. It's much simpler to use but once the data leaves the host, you can only pray to god (or the smurfs) that it gets to its destination.
And currently, youre using... TCP.. Which demands that you start off communication with a three-way-handshake (which you don't).
First of all I think you should try to print the exception by typing System.err.println(e); in your catch so you can try to determine what's going wrong. It could be that the server is not set to recieve data on port 9999.
It could also be that unless you send some data, the server closes the connection after some timout. Did you write the server side application as well?
You didn't get it or did you.I am designing an application which can act both as a server and a client depending on whether there is any other server on network.I am trying to scan all local ip addresses to check whether anyone on network has a server listening or not and if it finds one it joins the server and if it doesn't, it creates a new server and start listening for connections from other machines on network in continuation of the code i've shown i'm starting a serversocket if it was unable to join any other server.
By the way, i've modified my code.Plz tell me if it will work or not.Actually in place of ipaddress i've just entered ""...
CODE
try {
skt = new Socket([color=#FF0000]""[/color], 9999);
jLabel1.setText(skt.getInetAddress() + "");
} catch (IOException ex) {
connected = false;
}
it is working fine on my machine when i run 2 copies of this program.But i doubt that it will work on network...
I can attach my whole program if you want...
This post has been edited by saumya9888: 16 Aug, 2008 - 09:59 AM