0

I'm new to java and now I have a problem in using Ethernet port in Java . I have a device which can send and receive data by Ethernet . I connect it to a switch and when I enter its IP address in a browser I can see the data that the device sent ( the data is some HTML code ). But now I want to do it by a java application . If anyone can help me or send some sample code I would be grateful . thanks

5
  • 1
    What have you tried so far? WHat errors did you get? Can you show some code? Commented Jun 23, 2015 at 14:06
  • So you can access the data with a simple HTTP request? Commented Jun 23, 2015 at 14:09
  • 2
    possible duplicate of : stackoverflow.com/questions/5371943/… Commented Jun 23, 2015 at 14:12
  • I use the code that I found in this page and it did not work : stackoverflow.com/questions/25665423/… Commented Jun 23, 2015 at 16:16
  • yes I can send and receive data by using a web browser like chrome . Commented Jun 23, 2015 at 16:18

1 Answer 1

0

I think tutorials on socket programming will help you.
https://docs.oracle.com/javase/tutorial/networking/sockets/

A very brief code may look like this:

Socket socket = new Socket(ipAddressOfDevice); InputStream in = socket.getInputStream(); OutputStream out = socket.getOuputStream(); PrintWriter pw = new PrintWriter(out); pw.write(yourHttpRequest); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String oneLineOfInput = br.readLine(); System.out.println(oneLineOfInput); 
Sign up to request clarification or add additional context in comments.

1 Comment

I used this code but didn't work . actually it has some problem in : String oneLineOfInput = br.readLine(); because the code stop at this line ( no error ) .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.