View RSS Feed

Java Socket

Server Sockets

Rate this Entry
by , 04-25-2012 at 11:19 PM (510 Views)
One common question which arises in mind is that who listens at the socketís other end. Answer to this question is nobody unless server socket is set or pre existing service has been connected and an attempt to make connection would be failed. Principal constructor is :

Java Code:
ServerSocket(int port)
that makes a server socket which listen at specific port. To make a connection or set server socket, use this code:

Java Code:
import java.net.*;

SeverSocket sSoc = new ServerSocket(1024);

Socket in = sSoc.accept();
Server socket known as sSoc is created and then its accept() method is called. Here, code would be waiting till other process makes a connection with server socket by making an automatic client socket.

Submit "Server Sockets" to Facebook Submit "Server Sockets" to Digg Submit "Server Sockets" to del.icio.us Submit "Server Sockets" to StumbleUpon Submit "Server Sockets" to Google

Categories
Tutorial

Comments