This is my client code (J2ME):
SocketConnection sc = (SocketConnection) Connector.open("socket://localhost:4444");
sc.openOutputStream().write("test".getBytes());
sc.close();
And this is my server code (J2SE):
ServerSocket serverSocket = new ServerSocket(4444);
Socket clientSocket = serverSocket.accept();
OutputStream os = clientSocket.getOutputStream();
How would I go about creating a string representation of os?
InputStreamandOutputStreamare for byte sequences.ReaderandWriterare for character sequences, likeStrings.To turn an
OutputStreaminto aWriter, donew OutputStreamWriter(outputStream), or much better, usenew OutputStreamWriter(outputStream, Charset)to specify aCharset, which describes a way of converting between characters and bytes.(The other direction,
InputStreamReader, is similar.)