Solved

Java Network Programming

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

828 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