• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Problem when send more messagge to socket

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!