You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by KK <Ka...@gmx.de> on 2011/04/08 15:22:29 UTC

Question about multi client ability on server side

Hello,

I am a new thrift user since about 24 hours and have to say: I am thrilled.

While testing I have a scenario with a cpp server and a php client.

The server has a function like

  void sayHello(string &ret, const string &name, const int32_t age)
  {

char buffer[2];
sprintf(buffer, "%d", age);

if (strcmp(name.data(), "ABC") == 0)
{
while(1){ usleep(1000); }
}

ret.append("Hello ");
ret.append(name.c_str());
ret.append(" (");
ret.append(buffer);
ret.append(")");
  }

and the client looks like the following

  $socket = new TSocket('192.168.3.72', 9090);
  $transport = new TBufferedTransport($socket, 1024, 1024);
  $protocol = new TBinaryProtocol($transport);
  $client = new CalculatorClient($protocol);

  $transport->open();

  $hello = $client->sayHello("Test", 99);
  print $hello;

  $transport->close();

But when I copy the phpClient.php to phpClient2.php and uses "ABC" as name
for function "sayHello", the server will hang in that infinite loop and will
not give access to phpClient.php where name is "Test" (TException: TSocket:
timed out reading 4 bytes from 192.168.3.72:9090). So the server is blocked
by the client who opens function sayHello with parameter "ABC".

Is there any possibility to make the server "multi-client-able" that every
client gets its own instance?

Best regards, KK

Re: Question about multi client ability on server side

Posted by Bryan Duxbury <br...@rapleaf.com>.
You need to use a server implementation that supports threads. Most
languages' libraries provide a number of different server implementations,
but you probably want something with ThreadPool in the name.

On Fri, Apr 8, 2011 at 6:22 AM, KK <Ka...@gmx.de> wrote:

> Hello,
>
> I am a new thrift user since about 24 hours and have to say: I am thrilled.
>
> While testing I have a scenario with a cpp server and a php client.
>
> The server has a function like
>
>  void sayHello(string &ret, const string &name, const int32_t age)
>  {
>
> char buffer[2];
> sprintf(buffer, "%d", age);
>
> if (strcmp(name.data(), "ABC") == 0)
> {
> while(1){ usleep(1000); }
> }
>
> ret.append("Hello ");
> ret.append(name.c_str());
> ret.append(" (");
> ret.append(buffer);
> ret.append(")");
>  }
>
> and the client looks like the following
>
>  $socket = new TSocket('192.168.3.72', 9090);
>  $transport = new TBufferedTransport($socket, 1024, 1024);
>  $protocol = new TBinaryProtocol($transport);
>  $client = new CalculatorClient($protocol);
>
>  $transport->open();
>
>  $hello = $client->sayHello("Test", 99);
>  print $hello;
>
>  $transport->close();
>
> But when I copy the phpClient.php to phpClient2.php and uses "ABC" as name
> for function "sayHello", the server will hang in that infinite loop and
> will
> not give access to phpClient.php where name is "Test" (TException: TSocket:
> timed out reading 4 bytes from 192.168.3.72:9090). So the server is
> blocked
> by the client who opens function sayHello with parameter "ABC".
>
> Is there any possibility to make the server "multi-client-able" that every
> client gets its own instance?
>
> Best regards, KK
>