Jython socket typecasting problems

Mark Fink mark at mark-fink.de
Mon Feb 13 14:10:15 EST 2006


thanks to the help of this group I moved a tiny step forward. Obviously
it is not possible to resolve name localhost:
Type "copyright", "credits" or "license" for more information.
>>> import socket
>>> s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(localhost, 8080)
Traceback (innermost last):
  File "<console>", line 1, in ?
NameError: localhost
>>> s.connect((localhost, 8080))
Traceback (innermost last):
  File "<console>", line 1, in ?
NameError: localhost
>>> s.connect(('127.0.0.1', 8080))
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "D:\AUT_TEST\Jython21\Lib\socket.py", line 135, in connect
java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:507)

Unfortunately this is not the solution (I tried 127.0.0.1 before my
first post).
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?




More information about the Python-list mailing list