Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

Socket Programming

 
nayomi gunawardena
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
looks identical to http://www.coderanch.com/t/557081/java/java/Socket-Programming; closing this one.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic