Solved

Java Network Programming

Posted on 2012-03-12
3
244 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

759 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

20 Experts available now in Live!

Get 1:1 Help Now