Avatar of CCBRONET
CCBRONET
 asked on

Java Network Programming

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....
JavaNetworking Protocols

Avatar of undefined
Last Comment
Juan Carlos

8/22/2022 - Mon
CEHJ

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
RodSingh

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();
            }

      }
}
ASKER CERTIFIED SOLUTION
Juan Carlos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck