Forum Stats

  • 3,726,727 Users
  • 2,245,248 Discussions
  • 7,852,377 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem when send more messagge to socket

webgest
webgest Member Posts: 1

I develop an application in java for communicate with a ethernet printer. I use this code

Socket socket = new Socket(ip,port);

                  InputStream is = socket.getInputStream();

      InputStreamReader isr = new InputStreamReader(is);

  BufferedReader br = new BufferedReader(isr);

      OutputStream outStream = socket.getOutputStream();

   String messageString = "message1";

  outStream.write(messageString.getBytes());

  outStream.flush();

  outStream.close();

  br.close();

          socket.close();

For "message 1 " all it s ok but when i try to send "message2" the printer doesn t print the message. I need to close the connection and re-open the socket like this

socket = new Socket(ip,port);

                  InputStream is = socket.getInputStream();

      InputStreamReader isr = new InputStreamReader(is);

  BufferedReader br = new BufferedReader(isr);

      OutputStream outStream = socket.getOutputStream();

  String messageString = "message2";

  outStream.write(messageString.getBytes());

  outStream.flush();

  outStream.close();

  br.close();

          socket.close();

In this way work fine but if i send ten message i have to wait 10 second to have the ticket probably due to the time for open a new socket Thank you

Sign In or Register to comment.