CSR
CSR

Reputation: 820

Java listening on port

We want to capture the data which comes to the system on port say 7777.

public static void main(String[] args) {
        try {
            final ServerSocket serverSocket = new ServerSocket(7777);
            new Thread("Device Listener") {
                public void run() {
                    try {
                        System.out.println("Listener Running . . .");
                        Socket socket = null;
                        while ((socket = serverSocket.accept()) != null) {
                            System.out.println("| Incoming : "+ socket.toString());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                };
            }.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

We have a device which sends data to the port 7777, which comes with a native windows application. The windows native application is receiving data which comes from that device. We have to receive that data on port 7777 through our java project.

In the above code,

  1. The java server socket is created but no incoming connections are received from the device.

  2. The java server socket is receiving connections from telnet command.

  3. The data format which is used by the device and the other native application may be different, but atleast it has to be connected from java server socket. is it correct?

  4. how to receive the data which is transmitted to port 7777.

EDIT:

Ok, the data is received with UDP socket. it is 68 in length. The device documentation doesn't specify any methods to capture this data, because may be it is designed to work with the specified application. We can't contact the manufacturer also. is there any way (if possible) to know the format of incoming bytes. we have tried network sniffers but we cant understand the format.

Upvotes: 3

Views: 10773

Answers (2)

Brian Agnew
Brian Agnew

Reputation: 272277

If you're receiving from the telnet command, then I suspect you have a network-specific issue.

  1. your device isn't talking to the same ip address / hostname that you're configuring telnet with
  2. you have a routing or firewall issue
  3. is your device possibly using UDP rather than TCP ?

Upvotes: 5

user207421
user207421

Reputation: 310903

The java server socket is created but no incoming connections are received from the device.

So either there is a firewall in the way or the device isn't trying to connect to that port.

The java server socket is receiving connections from telnet command.

So the Java application is listening to that port.

The data format which is used by the device and the other native application may be different, but at least it has to be connected from java server socket. is it correct?

Yes.

how to receive the data which is transmitted to port 7777.

First you have to accept the connection. On the evidence here the device isn't connecting to port 7777 at all. I suggest some network sniffing is in order to see what it really is doing.

Upvotes: 3

Related Questions