Notes on Distributed Socket Servers

From mi-linux
Revision as of 15:15, 7 March 2011 by In0316 (talk | contribs) (New page: ...Back to 5CS004 == Things you can and cannot do with sockets == * Sockets cannot be ''serialized'' which means that you can send a socket as a message to an '''Actor''' object, if ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

...Back to 5CS004

Things you can and cannot do with sockets

  • Sockets cannot be serialized which means that you can send a socket as a message to an Actor object, if that actor is running on the same JVM, but NOT if the actor is a RemoteActor
  • You can have more than on SocketServer object running at once, like this:
   
var listener : ServerSocket = null
try {
    // Server socket for accepting new TCP connections.
    listener = new ServerSocket()
    // Tell the listener to "reuse" the address, so that other
    // SocketServers can use the same IP address and port.
    if (!listener.getReuseAddress()) {
        listener.setReuseAddress(true)
    }
    println("Reuse address is: " + listener.getReuseAddress())
    // Bind the listener to the IP address and port number.
    listener.bind(new InetSocketAddress(port))
    

However, you can only do this if either:

    • All of your actors containing SocketServer objects are running on different machines, or
    • Your actors are NOT RemoteActors.


But I'm just running this on my own machine...

If you are testing all of your code on one machine, it is probably best to stick to the sort of architecture that you saw in the DistributedTimeServer example, where you had concurrent servers and handlers, and distributed / remote Responder objects.

...Back to 5CS004