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

Masoud
  • 1
  • 1
  • 6

1 Answers1

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);
Iman
  • 1,017
  • 10
  • 26
  • 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 ) . – Masoud Jun 24 '15 at 07:23