[ Contact ] [ Links ] [ Previous : 57 / 60 : JAVA TCP/IP Socket Implementation ] [ Up ] [ Next : 59 / 60 : JAVA TCP/IP Socket Implementation (6) ]

JAVA TCP/IP Socket Implementation (5)

Server Actions

Instantiate a ServerSocket object

  1. Instantiate a ServerSocket object
  2. Receive connections from clients
  3. Communicate with clients
    1. Recieve data/requests
    2. Send data/replys
  4. Close the socket
  • Instantiating a ServerSocket object creates a socket ready to accept client connections
  • Replaces the socket(), listen(), and
    bind() functions in C / C++
  • Three common constructors, arguments are...
  1. port number
  2. port number, listener backlog
  3. port number, listener backlog and IP address
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.DataOutputStream;

ServerSocket acceptSock;                   // Declare the ServerSocket

//  Instantiate a ServerSocket using constructor that takes only the port number
try {
	acceptSock = new ServerSocket(13214);
}

catch(IOException ioe) {
	System.out.println("Error opening server socket: " + ioe.getMessage());
	return;
}
eScience
< Internetworked VR : Networking >
[ Contact ] [ Links ] [ Previous : 57 / 60 : JAVA TCP/IP Socket Implementation ] [ Up ] [ Next : 59 / 60 : JAVA TCP/IP Socket Implementation (6) ]

See the "Links" link above to find out the sources of the proposed informations
Pascal Vuylsteker / eScience / Computer Science / ANU
Last modified: 22/3/2005
TOC - Print
Send your comments at :
<pvk@vuylsteker.net>