Solved

Java Network Programming

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:
Suggested Courses

630 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