dcsimg
Write to socket
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Huamin_Wang
Posted On:   Monday, April 22, 2002 03:36 PM

Hi,

Would you please tell me how to write a string and a short number to a socket at once, that is by using one write statement.

Thanks, have a good one.

Huamin Wang

Re: Write to socket

Posted By:   Terry_Laurenzo  
Posted On:   Monday, April 22, 2002 05:13 PM

Try creating a ByteArrayOutputStream wrapped by a DataOutputStream. Write whatever you want to the DataOutputStream, then get the byte[] array from the ByteArrayOutputStream and write it to the socket's OutputStream.


Alternatively, if you are just trying to write the Ascii representation of the string and a number, make a String out of them(ie. "Some String" + 10). Wrap a PrintStream or a PrintWriter around your socket OutputStream and write through there.

About | Sitemap | Contact