Solved

Java Network Programming

Posted on 2012-03-12
3
245 Views
Last Modified: 2012-06-27
Would like to set up a network listener for a particular ip address so that when a connection is established to that particular destination certain programs can be executed....


Thanks In Advance....
0
Comment
Question by:CCBRONET
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 37710262
Then you'll need some kind of proxy server. Services are provide via an address AND a port. You need to listen there and then forward to the real service
0
 
LVL 1

Expert Comment

by:RodSingh
ID: 37710468
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class NetworkListener {

      private static int LISTENER_ADDRESS = 4446;
      public static void main(String[] args) {

            try {
                  ServerSocket serverSocket = new ServerSocket( LISTENER_ADDRESS);                  
                  while (true) {
                        System.out.println("The listener is ready to accept connection...");
                        Socket clientSocket = serverSocket.accept();
                        Thread thread = new Thread() {
                              public void run() {
                                    System.out.println("Execute your program");
                              }
                        };
                        thread.start();
                  }
            } catch (IOException e) {            
                  e.printStackTrace();
            }

      }
}
0
 
LVL 3

Accepted Solution

by:
jcgd earned 500 total points
ID: 37715355
// to bind a specif ip address

            InetAddress addrIpName = InetAddress.getByName("172.30.1.18");
//      or
//      InetAddress addrName = InetAddress.getByName("myhost.name");
//    or
//            InetAddress addrIp = InetAddress.getByAddress(new byte[] { (byte)172,30,1,18});
            int port = 4446;
                int bl = 5;
            ServerSocket serverSocket = new ServerSocket(port,bl,addrIpName);
0

Featured Post

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EIGRP on point-to-point vlan 14 65
FILEZILLA Client "default"? 2 28
couple of eclipse 5 19
MySQL  on Tomcat 8 26
I know for anybody starting from Beginner to Expert in Networking knows what OSI model. But this tutorial is for freshers or those who are new to networking world. Why I am putting OSI in such simple and compact manner is because it enables you to k…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now