Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BE5AD200CFA for ; Tue, 5 Sep 2017 09:48:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BCEE6165734; Tue, 5 Sep 2017 07:48:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B509A165731 for ; Tue, 5 Sep 2017 09:48:10 +0200 (CEST) Received: (qmail 63949 invoked by uid 500); 5 Sep 2017 07:48:09 -0000 Mailing-List: contact dev-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list dev@thrift.apache.org Received: (qmail 63938 invoked by uid 99); 5 Sep 2017 07:48:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Sep 2017 07:48:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CFDBB1826F5 for ; Tue, 5 Sep 2017 07:48:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id YNlI2WifT7VD for ; Tue, 5 Sep 2017 07:48:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 4E4635FBB1 for ; Tue, 5 Sep 2017 07:48:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 78921E065D for ; Tue, 5 Sep 2017 07:48:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 25CEC2414B for ; Tue, 5 Sep 2017 07:48:00 +0000 (UTC) Date: Tue, 5 Sep 2017 07:48:00 +0000 (UTC) From: "Walter Weinmann (JIRA)" To: dev@thrift.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (THRIFT-4312) Tutorial: Erlang client cannot connect to Python server: exception error: econnrefused MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 05 Sep 2017 07:48:11 -0000 [ https://issues.apache.org/jira/browse/THRIFT-4312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Walter Weinmann updated THRIFT-4312: ------------------------------------ Description: h3. Connecting the Erlang client with the Python server gives connection error: h3. h4. Erlang client: h4. h4. {{ -module(client). -include("calculator_thrift.hrl"). -export([t/0]). p(X) -> io:format("~p~n", [X]), ok. t() -> Port = 9090, {ok, Client0} = thrift_client_util:new("localhost", Port, calculator_thrift, []), {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []), io:format("ping~n", []), {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]), io:format("1+1=~p~n", [Sum]), {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]), io:format("1+4=~p~n", [Sum1]), Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT, num1=15, num2=10}, {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]), io:format("15-10=~p~n", [Diff]), {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]), io:format("Log: ~p~n", [Log]), Client6 = try Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE, num1=1, num2=0}, {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]), io:format("LAME: exception handling is broken~n", []), ClientS1 catch throw:{ClientS2, Z} -> io:format("Got exception where expecting - the " ++ "following is NOT a problem!!!~n"), p(Z), ClientS2 end, {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []), io:format("zip~n", []), {_Client8, ok} = thrift_client:close(Client7), ok. }} h4. Python server: h4. {{ #!/usr/bin/env python from tutorial import Calculator from tutorial.ttypes import InvalidOperation, Operation from shared.ttypes import SharedStruct from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from thrift.server import TServer class CalculatorHandler: def __init__(self): self.log = {} def ping(self): print('ping()') def add(self, n1, n2): print('add(%d,%d)' % (n1, n2)) return n1 + n2 def calculate(self, logid, work): print('calculate(%d, %r)' % (logid, work)) if work.op == Operation.ADD: val = work.num1 + work.num2 elif work.op == Operation.SUBTRACT: val = work.num1 - work.num2 elif work.op == Operation.MULTIPLY: val = work.num1 * work.num2 elif work.op == Operation.DIVIDE: if work.num2 == 0: x = InvalidOperation() x.whatOp = work.op x.why = 'Cannot divide by 0' raise x val = work.num1 / work.num2 else: x = InvalidOperation() x.whatOp = work.op x.why = 'Invalid operation' raise x log = SharedStruct() log.key = logid log.value = '%d' % (val) self.log[logid] = log return val def getStruct(self, key): print('getStruct(%d)' % (key)) return self.log[key] def zip(self): print('zip()') if __name__ == '__main__': handler = CalculatorHandler() processor = Calculator.Processor(handler) transport = TSocket.TServerSocket(port=9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) # You could do one of these for a multithreaded server # server = TServer.TThreadedServer( # processor, transport, tfactory, pfactory) # server = TServer.TThreadPoolServer( # processor, transport, tfactory, pfactory) print('Starting the server...') server.serve() print('done.') }} h4. Runtime protocol: h4. {{ EBIN Path : D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\erlang_and_thrift\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\jsx\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\thrift\ebin ------------------------------------------ Eshell V9.0 (abort with ^G) 1> client:t(). ** exception error: no match of right hand side value {error,econnrefused} in function client:t/0 (d:/SoftDevelopment/Projects/erlang-and-thrift_idea/erlang-and-thrift/_build/default/lib/erlang_and_thrift/src/client.erl, line 33) 2> Terminate batch job (Y/N)? y D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift>tcping64 localhost 9090 Probing ::1:9090/tcp - Port is open - time=0.580ms Probing ::1:9090/tcp - Port is open - time=0.622ms Probing ::1:9090/tcp - Port is open - time=1.038ms Probing ::1:9090/tcp - Port is open - time=1.050ms Ping statistics for ::1:9090 4 probes sent. 4 successful, 0 failed. Approximate trip times in milli-seconds: Minimum = 0.580ms, Maximum = 1.050ms, Average = 0.822ms }} was: h3. Connecting the Erlang client with the Python server gives connection error: h3. h4. Erlang client: h4. h4. {{ -module(client). -include("calculator_thrift.hrl"). -export([t/0]). p(X) -> io:format("~p~n", [X]), ok. t() -> Port = 9090, {ok, Client0} = thrift_client_util:new("localhost", Port, calculator_thrift, []), {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []), io:format("ping~n", []), {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]), io:format("1+1=~p~n", [Sum]), {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]), io:format("1+4=~p~n", [Sum1]), Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT, num1=15, num2=10}, {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]), io:format("15-10=~p~n", [Diff]), {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]), io:format("Log: ~p~n", [Log]), Client6 = try Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE, num1=1, num2=0}, {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]), io:format("LAME: exception handling is broken~n", []), ClientS1 catch throw:{ClientS2, Z} -> io:format("Got exception where expecting - the " ++ "following is NOT a problem!!!~n"), p(Z), ClientS2 end, {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []), io:format("zip~n", []), {_Client8, ok} = thrift_client:close(Client7), ok. }} h4. Python server: h4. {{ #!/usr/bin/env python # import glob # import sys # sys.path.append('gen-py') # sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0]) from tutorial import Calculator from tutorial.ttypes import InvalidOperation, Operation from shared.ttypes import SharedStruct from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from thrift.server import TServer class CalculatorHandler: def __init__(self): self.log = {} def ping(self): print('ping()') def add(self, n1, n2): print('add(%d,%d)' % (n1, n2)) return n1 + n2 def calculate(self, logid, work): print('calculate(%d, %r)' % (logid, work)) if work.op == Operation.ADD: val = work.num1 + work.num2 elif work.op == Operation.SUBTRACT: val = work.num1 - work.num2 elif work.op == Operation.MULTIPLY: val = work.num1 * work.num2 elif work.op == Operation.DIVIDE: if work.num2 == 0: x = InvalidOperation() x.whatOp = work.op x.why = 'Cannot divide by 0' raise x val = work.num1 / work.num2 else: x = InvalidOperation() x.whatOp = work.op x.why = 'Invalid operation' raise x log = SharedStruct() log.key = logid log.value = '%d' % (val) self.log[logid] = log return val def getStruct(self, key): print('getStruct(%d)' % (key)) return self.log[key] def zip(self): print('zip()') if __name__ == '__main__': handler = CalculatorHandler() processor = Calculator.Processor(handler) transport = TSocket.TServerSocket(port=9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) # You could do one of these for a multithreaded server # server = TServer.TThreadedServer( # processor, transport, tfactory, pfactory) # server = TServer.TThreadPoolServer( # processor, transport, tfactory, pfactory) print('Starting the server...') server.serve() print('done.') }} h4. Runtime protocol: h4. {{ EBIN Path : D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\erlang_and_thrift\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\jsx\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\thrift\ebin ------------------------------------------ Eshell V9.0 (abort with ^G) 1> client:t(). ** exception error: no match of right hand side value {error,econnrefused} in function client:t/0 (d:/SoftDevelopment/Projects/erlang-and-thrift_idea/erlang-and-thrift/_build/default/lib/erlang_and_thrift/src/client.erl, line 33) 2> Terminate batch job (Y/N)? y D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift>tcping64 localhost 9090 Probing ::1:9090/tcp - Port is open - time=0.580ms Probing ::1:9090/tcp - Port is open - time=0.622ms Probing ::1:9090/tcp - Port is open - time=1.038ms Probing ::1:9090/tcp - Port is open - time=1.050ms Ping statistics for ::1:9090 4 probes sent. 4 successful, 0 failed. Approximate trip times in milli-seconds: Minimum = 0.580ms, Maximum = 1.050ms, Average = 0.822ms }} > Tutorial: Erlang client cannot connect to Python server: exception error: econnrefused > -------------------------------------------------------------------------------------- > > Key: THRIFT-4312 > URL: https://issues.apache.org/jira/browse/THRIFT-4312 > Project: Thrift > Issue Type: Bug > Components: Tutorial > Affects Versions: 0.10.0 > Environment: Windows 10 > Erlang OTP 20 > Python 3.6.2 > Reporter: Walter Weinmann > Priority: Critical > > h3. Connecting the Erlang client with the Python server gives connection error: > h3. > h4. Erlang client: > h4. > h4. > {{ > -module(client). > -include("calculator_thrift.hrl"). > -export([t/0]). > p(X) -> > io:format("~p~n", [X]), > ok. > t() -> > Port = 9090, > {ok, Client0} = thrift_client_util:new("localhost", > Port, > calculator_thrift, > []), > {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []), > io:format("ping~n", []), > {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]), > io:format("1+1=~p~n", [Sum]), > {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]), > io:format("1+4=~p~n", [Sum1]), > Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT, > num1=15, > num2=10}, > {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]), > io:format("15-10=~p~n", [Diff]), > {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]), > io:format("Log: ~p~n", [Log]), > Client6 = > try > Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE, > num1=1, > num2=0}, > {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]), > io:format("LAME: exception handling is broken~n", []), > ClientS1 > catch > throw:{ClientS2, Z} -> > io:format("Got exception where expecting - the " ++ > "following is NOT a problem!!!~n"), > p(Z), > ClientS2 > end, > {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []), > io:format("zip~n", []), > {_Client8, ok} = thrift_client:close(Client7), > ok. > }} > h4. Python server: > h4. > {{ > #!/usr/bin/env python > from tutorial import Calculator > from tutorial.ttypes import InvalidOperation, Operation > from shared.ttypes import SharedStruct > from thrift.transport import TSocket > from thrift.transport import TTransport > from thrift.protocol import TBinaryProtocol > from thrift.server import TServer > class CalculatorHandler: > def __init__(self): > self.log = {} > def ping(self): > print('ping()') > def add(self, n1, n2): > print('add(%d,%d)' % (n1, n2)) > return n1 + n2 > def calculate(self, logid, work): > print('calculate(%d, %r)' % (logid, work)) > if work.op == Operation.ADD: > val = work.num1 + work.num2 > elif work.op == Operation.SUBTRACT: > val = work.num1 - work.num2 > elif work.op == Operation.MULTIPLY: > val = work.num1 * work.num2 > elif work.op == Operation.DIVIDE: > if work.num2 == 0: > x = InvalidOperation() > x.whatOp = work.op > x.why = 'Cannot divide by 0' > raise x > val = work.num1 / work.num2 > else: > x = InvalidOperation() > x.whatOp = work.op > x.why = 'Invalid operation' > raise x > log = SharedStruct() > log.key = logid > log.value = '%d' % (val) > self.log[logid] = log > return val > def getStruct(self, key): > print('getStruct(%d)' % (key)) > return self.log[key] > def zip(self): > print('zip()') > if __name__ == '__main__': > handler = CalculatorHandler() > processor = Calculator.Processor(handler) > transport = TSocket.TServerSocket(port=9090) > tfactory = TTransport.TBufferedTransportFactory() > pfactory = TBinaryProtocol.TBinaryProtocolFactory() > server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) > # You could do one of these for a multithreaded server > # server = TServer.TThreadedServer( > # processor, transport, tfactory, pfactory) > # server = TServer.TThreadPoolServer( > # processor, transport, tfactory, pfactory) > print('Starting the server...') > server.serve() > print('done.') > }} > h4. Runtime protocol: > h4. > {{ > EBIN Path : D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\erlang_and_thrift\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\jsx\ebin D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift\_build\default\lib\thrift\ebin > ------------------------------------------ > Eshell V9.0 (abort with ^G) > 1> client:t(). > ** exception error: no match of right hand side value {error,econnrefused} > in function client:t/0 (d:/SoftDevelopment/Projects/erlang-and-thrift_idea/erlang-and-thrift/_build/default/lib/erlang_and_thrift/src/client.erl, line 33) > 2> Terminate batch job (Y/N)? y > D:\SoftDevelopment\Projects\erlang-and-thrift_idea\erlang-and-thrift>tcping64 localhost 9090 > Probing ::1:9090/tcp - Port is open - time=0.580ms > Probing ::1:9090/tcp - Port is open - time=0.622ms > Probing ::1:9090/tcp - Port is open - time=1.038ms > Probing ::1:9090/tcp - Port is open - time=1.050ms > Ping statistics for ::1:9090 > 4 probes sent. > 4 successful, 0 failed. > Approximate trip times in milli-seconds: > Minimum = 0.580ms, Maximum = 1.050ms, Average = 0.822ms > }} -- This message was sent by Atlassian JIRA (v6.4.14#64029)