thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hannes Baldursson <hann...@gmail.com>
Subject C# threaded server
Date Fri, 27 Mar 2009 06:48:33 GMT
Hi all,

I'm trying to create a threaded server for a simple hangman game written in
C#. It's working fine for a single client but multiple clients seem to share
the game instance instead of each having a unique one.

The code I use to start the server is:

                bool useBufferedSockets = false;
>                 int port = 9090;
>
>
>                 // Processor
>               *  HangmanHandler hangmanHandler = new HangmanHandler();*
>                 HangmanRPC.Processor hangmanProcessor = new
> HangmanRPC.Processor(hangmanHandler);
>
>                 // Transport
>                 TServerSocket tServerSocket = new TServerSocket(port, 0,
> useBufferedSockets);
>
>                 TServer serverEngine;
>
>                 // Simple Server
>                 //serverEngine = new TSimpleServer(hangmanProcessor,
> tServerSocket);
>
>                 // ThreadPool Server
>                 // serverEngine = new TThreadPoolServer(testProcessor,
> tServerSocket);
>
>                 // Threaded Server
>                  serverEngine = new TThreadedServer(hangmanProcessor,
> tServerSocket);
>
>                 hangmanHandler.server = serverEngine;
>
>                 // Run it
>                 Console.WriteLine("Starting the server on port " + port +
> (useBufferedSockets ? " with buffered socket" : "") + "...");
>                 serverEngine.Serve();
>

HangmanRPC is the service generated by the thrift compiler.
HangmanHandler is the implementation that responds to the RPC commands and
contains an object of HangmanGame which is the code for the game instance.

The problem is that the HangmanGame object is shared between multiple
clients. What is the ideal place for HangmanGame so it creates a unique
instance for each client?


Thanks in advance,
Hannes Baldursson

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message