Socket Programming

ivanthepro
ivanthepro used Ask the Experts™
on
Hi,

Im new to java. Can someone pls tell me can Java Socket Programs be used over internet? If so, how do we fix the server's ip addy if the client makes frequent connections and the server restarts frequently and thus need ip addy is changed frequently...
Is there any way to fix this prob? Or is there any way to fix the server's ip?

regards
Ivan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You mean that server's IP is dynamic??
You can apply a dynamic domain name for IP address.
The client use the domain name to request for connect.
The following is sample code:
/* Server side */
import java.net.*;
public class Server implements Runnable{
   ServerSocket server;
   public Server() {
      try {
        server = new ServerSokcet(1234);
      } catch(Exception e){e.printStackTrace();}
   }
   public void run() {
      try {
         Socket client;
         while (true) {
             client = server.accept();
             // ... continue to do other things.
         }
      } catch(Exception e){e.printStackTrace();}
   }
}

/* Client side */
import java.net.*;
public class Client {
   public static void main(String[] args) {
      try {
          Socket client = new Socket("your.domain.name", 1234);
          // ... continue to do other things.
      } catch(Exception e){e.printStackTrace();}
   }
}
ivanthepro:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for Lavendermpl

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial