View RSS Feed

Java Socket

Client Sockets

Rate this Entry
by , 04-25-2012 at 11:18 PM (662 Views)
Client sockets are handled by a class which is in package. This line would be included generally;

So that package methodís short names could be used. Number of constructors could be used for creation of new [client] socket. This depends upon the specific circumstances. Simplest one is:
Java Code:
 Socket(String host, int port)
that connects to machine hostís port. For example,
Java Code:
Socket s = new Socket("", 1024);
To read or write to/from socket, Standard Java I/O methods are used. This code given below is used to open the socket and also to attach the input or output streams with it:
Java Code:

Socket s = new Socket("", 1024);
BufferedReader in = new BufferedReader(
               new InputStreamReader(s.getInputStream()));
PrintStream out =
            new PrintStream(s.getOutputStream());

Submit "Client Sockets" to Facebook Submit "Client Sockets" to Digg Submit "Client Sockets" to Submit "Client Sockets" to StumbleUpon Submit "Client Sockets" to Google