Jython socket typecasting problems

Steve Holden steve at holdenweb.com
Mon Feb 13 16:38:05 EST 2006


Kent Johnson wrote:
> Mark Fink wrote:
> 
>>I added the two print lines as recommended:
>>        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>        print type(self.host), repr(self.host)
>>        print type(self.port), repr(self.port)
>>        self.socket.connect((self.host, self.port))
>>        self.socketOutput = self.socket.getOutputStream()
>>
>>And more specific information:
>>D:\AUT_TEST\workspace\JyFIT\fit>jython JyFitServer2.py 127.0.0.1 1234
>>12
>>['JyFitServer2.py', '127.0.0.1', '1234', '12']
>>127.0.0.1
>>org.python.core.PyString '127.0.0.1'
>>org.python.core.PyString '1234'
>>Traceback (innermost last):
>>  File "JyFitServer2.py", line 148, in ?
>>  File "JyFitServer2.py", line 31, in run
>>  File "JyFitServer2.py", line 98, 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
>>
>>No casting from string to string?? I learned that there is no such
>>thing as explicit typecasting. What to do?
> 
> 
> The problem is that the second arg is not an int. The second problem is 
> that the error message errorneously points to the first arg. See my 
> earlier post.
> 

OK, so presumably you've worked out that where you assign

     self.port = something

you need to use

     self.port = int(something)

That should do it - Python doesn't have implicit type conversion like 
Perl does, but there are plenty of conversion functions available. That 
error message really wasn't helpful, was it?

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list