Jython socket typecasting problems

Mark Fink mark at mark-fink.de
Sat Feb 11 12:16:42 EST 2006


I try to port a server application to Jython. At the moment I use
Jython21\Lib\socket.py
Currently I do face problems with casting the string "localhost" to the
desired value:
D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py localhost 1234
23
['fit/JyFitServer2.py', 'localhost', '1234', '23']
localhost
Traceback (innermost last):
  File "fit/JyFitServer2.py", line 146, in ?
  File "fit/JyFitServer2.py", line 31, in run
  File "fit/JyFitServer2.py", line 96, in establishConnection
  File "D:\AUT_TEST\Jython21\Lib\socket.py", line 135, in connect
TypeError: java.net.Socket(): 1st arg can't be coerced to
java.net.InetAddress or String

The cast to Integer for the port does not work either:

D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py "" 1234 23
['fit/JyFitServer2.py', '', '1234', '23']

Traceback (innermost last):
  File "fit/JyFitServer2.py", line 146, in ?
  File "fit/JyFitServer2.py", line 31, in run
  File "fit/JyFitServer2.py", line 96, in establishConnection
  File "D:\AUT_TEST\Jython21\Lib\socket.py", line 135, in connect
TypeError: java.net.Socket(): 2nd arg can't be coerced to int

This is the code section of my server class (I cut this from a Python
example):
    def establishConnection(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect((self.host, self.port))
Do I have to use explicit typecasting? How can this be achieved?




More information about the Python-list mailing list