Kunal981
Kunal981

Reputation: 51

Could not read bytes ERROR after setting up Thrift

I have set up Thrift on my local system - windows 7 , PHP 5.3.8, Apache 2.2.21, Thrift 0.80,APC . I have tried to run the Client/Server thrift programs generated from Thrift compiler however none of the programs work. Each one gives me an error 'TSocket: Could not read 4 bytes from "localhost/path_to_client port 80" '.

I have enabled Socket extensions for PHP and tried using THttpClient and TSocket classes but none of these are working. I have switched Protocol classes from TBinaryProtocol to TBinaryProtocolAccelerated with no results.

I have gone through core classes of Thrift and I see that '_handle' actually doesn't points to a file rather it points to 'localhost'. I have tried giving it a file path but it still doesn't works.

I don't have much experience in Socket programming, however I feel that I am doing most of things correctly.

Your help on the same will be highly appreciated.

Upvotes: 0

Views: 2153

Answers (1)

Kunal981
Kunal981

Reputation: 51

I was able to resolve this issue and here is how -:

  1. First and foremost the syntax to generate PHP code from Thrift compiler is thrift --gen php*:server* yourfile.thrift . I was missing :server from the code. This wasn't mentioned in Thrift documentation

  2. Include the generated PHP file from Thrift compiler in your client and server file .

  3. Your server file should implement the Thrift interface.

  4. Make sure you start your Thrift server by executing the server file first. Make an object of yourclassProcessor file and open the transport layer. You will find this in thrift php tutorial.

  5. Call the server functions from your client file as given in examples.

Note- Make sure that you understand the functions return types well enough in Thrift.

Regards Kunal

Upvotes: 2

Related Questions