Re: How to Read from a socket ?? Code Snippet
public void run() {
// Create the server listening socket for port 1234
try{
ServerSocketConnection scn = (ServerSocketConnection)Connector.open("socket://:1234");
// Wait for a connection.
SocketConnection sc = (SocketConnection) scn.acceptAndOpen();
// Set application specific hints on the socket.
sc.setSocketOption(SocketConnection.DELAY, 0);
sc.setSocketOption(SocketConnection.LINGER, 0);
sc.setSocketOption(SocketConnection.KEEPALIVE, 0);
sc.setSocketOption(SocketConnection.RCVBUF, 128);
sc.setSocketOption(SocketConnection.SNDBUF, 128)
// Get the input stream of the connection.
DataInputStream is = sc.openDataInputStream();
// Get the output stream of the connection.
DataOutputStream os = sc.openDataOutputStream();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
Last edited by Ojasviharsola : 04-24-2012 at 05:02 AM.
|