wood burning stoves*
The moose likes Java in General and the fly likes Socket Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Socket Programming

nayomi gunawardena
Greenhorn

Joined: Sep 17, 2011
Posts: 6
Client implementation

import java.net.Socket;

public class MyClient {
public static void main(String[] args) {
try {
Socket socket = new Socket("127.0.0.1", 20000);
} catch(Exception e) {
// Exercise: Figure out the individual exceptions that can be thrown and when and why it would happen
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}




server implementation
import java.net.ServerSocket;

public class MyServer {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(20000); // bind to the port
} catch(Exception e) {
// Exercise: again, catch the individual exceptions and learn how and why they're thrown
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}


Server is run..Then the client is run..Both get connected..But at the end when the netstat is used..the port 20000 is not shown..why is that? Please help me
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
looks identical to http://www.coderanch.com/t/557081/java/java/Socket-Programming; closing this one.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket Programming
 
Similar Threads
java socket programming
Why should I use a new Socket to interrupt serverSocket.accept() ?
Chat At Server Part Both write and read at the same time?
Socket Programming
Help need for client server program