Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket Programming

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
looks identical to https://coderanch.com/t/557081/java/java/Socket-Programming; closing this one.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic