netbula.ORPC

Class TCPServer

Implemented Interfaces:
Runnable

public class TCPServer
extends Server

This class reprsents a TCP server. Usage sample:
         Svc svc = new msgsvc();

         TCPServer tcpserv = new TCPServer(8899, svc);
         TCPServer tcpserv = new TCPServer(server_socket, svc);

         if(tcpserv.unregister() == false ) {
            System.out.println("Fail to unregister tcp server");
         }

         if(tcpserv.register() == false ) {
            System.out.println("Fail to register tcp server");
         }else {
            System.out.println("registered TCP server on port:"+tcpserv.getPort());

            //run the TCP server in its own thread
            Thread t1 = new Thread(tcpserv);
            t1.start();
            System.out.println("Tcp server running");
         }

Constructor Summary

TCPServer(ServerSocket ss, Svc mysvc)
Use a bound server socket to create a TCP server.
TCPServer(int portn, Svc mysvc)
Construct a TCP server with an RPC service at a given port.

Method Summary

void
run()
Run the TCP server.

Methods inherited from class netbula.ORPC.Server

assignFixedThreadPool, getExecutorSvc, getPort, getProg, getSvc, getVers, isTCP, register, setExecutorSvc, setSvc, unregister

Constructor Details

TCPServer

public TCPServer(ServerSocket ss,
                 Svc mysvc)
            throws rpc_err
Use a bound server socket to create a TCP server. This method allows one to run a server on an existing server socket.
Parameters:
ss - a bound socket
mysvc - the RPC service.

TCPServer

public TCPServer(int portn,
                 Svc mysvc)
            throws rpc_err
Construct a TCP server with an RPC service at a given port.
Parameters:
portn - the desired port number, if this is 0, use any free port.
mysvc - the RPC service.

Method Details

run

public void run()
Run the TCP server. When this method is called, the thread enters an infinite loop to take RPC calls.