Hi.

I am thrift user too (just to warn you). Thrift library will never create
new instance of HangmanGame. I have the same problem too. I see 2 solutions.
First, you can write your own library that will create new processor for
each client. Or, you can use thread local storage to store data related to
different clients. I use TLS because I didn't want to rewrite the library.

Best wishes, Franis Sirkovic.

On Fri, Mar 27, 2009 at 7:48 AM, Hannes Baldursson <[email protected]>wrote:

> 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
>

Reply via email to