Start servers and clients
Cd ~ /Thrift-0.8.0/Thrift-R --Gen py tutorial. Thrift # generateCodeCD py./Pythonserver. py # Start the server CD~ /Thrift-0.8.0/Py./Pythonclient. py # Start the client in another shell window
As a result, an error occurs when the server is started.
Shujunli @ mysvr1 :~ /Thrift- 0.8 . 0 /Tutorial/Py $ ./ Pythonserver. py starting the server... traceback (most recent call Last ): File " ./Pythonserver. py " , Line 95 , In <Module> Server. Serve () File " /Usr/lib/python2.7/Site-packages/thrift/Server/tserver. py " , Line 74 , In Serve self. servertransport. Listen () File " /Usr/lib/python2.7/Site-packages/thrift/transport/tsocket. py " , Line 136 , In Listen res0 = Self. _ resolveaddr () File " /Usr/lib/python2.7/Site-packages/thrift/transport/tsocket. py " , Line 31 , In _ Resolveaddr return socket. getaddrinfo (self. Host, self. Port, socket. af_unspec, socket. sock_stream, 0 , Socket. ai_passive | Socket. ai_addrconfig) typeerror: getaddrinfo () argument 1 Must be String Or none
Let's take a look at file "pythonserver. py" and line 95.
Transport = tsocket. tserversocket (9090)
Let's look at the tserversocket source code
Def _ Init __(Self, host = none, Port = 9090, unix_socket = none ):
This is because of its initialization function. The first parameter is host, and the second parameter is port. Therefore, it is not feasible to save host. PY ", line 95 changed:
Transport = tsocket. tserversocket ('Localhost', 9090)
Or
Transport = tsocket. tserversocket (Port = 9090)
To solve the problem.