Solved

Java Network Programming

Posted on 2012-03-12
3
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

SSL is a very common protocol used these days when browsing the web.  The purpose is to provide security to communication, but how does it do it?  There are several pieces at work that have to be setup before SSL will even work and it requires both …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

752 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