File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 42371
    
  64
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