Server Side Programming
Server Side Programming
Programming
Creating a Server
CONTENTS
Accepting Connection
from browsers
CREATING A WEB SERVER
Create a ServerSocket object.
ServerSocket listenSocket =
new ServerSocket(portNumber);
2. CREATE A SOCKET OBJECT FROM THE
SERVER SOCKET
Many servers allow multiple connections, continuing to accept
connections until some termination condition is reached. The
Server Socket accept method blocks until a connection is
established, then returns a normal Socket object. Here is the
basic idea:
while(someCondition)
{ Socket server listenSocket.accept();
doSomethingWith(server);
}
3. CREATE AN I/P STREAM TO READ I/P
FROM THE CLIENT.
Once you have a Socket, you can use the socket in the same
way as with the client code
In the client section, a BufferedReader is more efficient to use
underneath the InputStreamReader, as follows:
server.close();
ACCEPTING THE CONNECTION
FROM BROWSER
Suppose the test program is started on port 8088 of
system1.com: