Answer the question
In order to leave comments, you need to log in
How to read data in Java from ethernet port?
I’m not looking for a ready-made solution, at least help in which direction to look / dig (maybe I’m setting up the converter in the wrong way, or vice versa on the other side of the problem).
There is a sensor that sends data about its location to the moxa NPort 5650-8-DTL converter, via com port, and it transmits the same data via ethernet to the computer. You need to read the data that comes. I tried to do it in java using a socket, but due to my poor knowledge of networks, I'm not sure that I'm reading what I need. Here is the first screen of the port settings. . On my computer, I set 192.168.10.1 and in wireshark I see how something goes with the ip that is on the converter. .
String hostname = "192.168.10.4";
int port = 4004;
try (Socket socket = new Socket(hostname, port)) {
InputStream input = socket.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
int character;
StringBuilder data = new StringBuilder();
while ((character = reader.read()) != -1) {
data.append((char) character);
}
System.out.println(data);
} catch (UnknownHostException ex) {
System.out.println("Server not found: " + ex.getMessage());
} catch (IOException ex) {
System.out.println("I/O error: " + ex.getMessage());
}
Answer the question
In order to leave comments, you need to log in
https://en.wikipedia.org/wiki/Berkeley_Sockets
www.java2s.com/Tutorials/Java/Java_Network/0020__J... must be added
socket.bind(new InetSocketAddress("localhost", port));
socket.connect(new InetSocketAddress("localhost", port));
We must first understand the roles. Are you a client or a server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question