2

I've compiled python version 2.7 for mobile devices using marmalade C++

{ In this question there is working and non-working example code }

My sockets module can:

  • Converts host names to dns addresses (getaddrinfo ok)
  • Check for connection a to host over a specified port (.connect_ex ok)

Cannot do a full connection; issue:

Python Documentation:
socket.create_connection(address[, timeout[, source_address]])

For some reason when I use socket.create_connection (.connect method), the 'address' tuple containing my IP address and port, drops the port and only contains the address when doing a full connection, which makes the socket connect to say xx.xx.xx.xx:0

INPUT using .connect(sockaddr)

connectExample.py

import urllib2
response = urllib2.urlopen('http://virtuhorizon.com:80')
print response.info()
html = response.read()
response.close()

Debugging statements added, excerpt from httplib.py )

...
def connect(self):
    print "===From: httplib ======IP=======: "+str(self.host)
    print "===From: httplib ======PORT=====: "+str(self.port)
    self.sock = socket.create_connection((self.host,self.port),
                                          self.timeout, self.source_address
...

socket.py excerpt (create_connection definition): http://pastebin.com/LpWvbFB9

socketmodule.c excerpt (connection methods): http://www.diffchecker.com/xuyteaed

OUTPUT [doesn't work]

(I added some print statements to the httplib just before create connection):


>>> ===From: httplib ======IP=======: 37.34.63.4
>>> ===From: httplib ======PORT=====: 80
>>> ('37.34.63.4', 80)
>>> <object object at 0xc1b74b0>
>>> None

SOCKET: s3eInetAton: '37.34.63.4'
IWCRT: open 100
SOCKET: s3eSocketCreate -> p=0x00b20d9c id=3000
IWCRT: connect: 100

SOCKET: s3eSocketConnect: 0x00b20d9c -> 37.34.63.4 :0

ERROR: S3E_SOCKET_ERR_PARAM in s3eSocketConnect
SOCKET: TryConnect error: 10049
SOCKET: NotifyConnect: 3000 0x00b20d9c
SOCKET: Connect: FAILED (1: S3E_SOCKET_ERR_PARAM in s3eSocketConnect)
IWCRT: close 100
SOCKET: s3eSocketClose: 0x00b20d9c open=1
FILE: s3eFileOpen('/pythonHome/Lib/urllib2.py', 'rb') succeeded, id=1027 p=0x00a7dda8

>>> return self.do_open(httplib.HTTPConnection, req)

>>> raise URLError(err)

07/07/14 09:03:57.144: [0xfa0] IWCRT: close 3
07/07/14 09:03:57.159: [0xfa0] FILE: s3eFileClose h=0x00a7dec4

>>> urllib2.URLError: <urlopen error [Errno 22] Invalid argument>

notice that the port the socket is connecting on is now 0

now if i use coonect_ex, the port is left unchanged and the connection goes through

INPUT using .connect_ex(sockaddr)

import socket
import sys

remoteServer    = "virtuhorizon.com"
remoteServerIP  = socket.gethostbyname(remoteServer)

print "Please wait, scanning remote host", remoteServerIP

try:
    for port in range(79,81):  
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((remoteServerIP, port))
        if result == 0:
            print "Port {}: \t Open".format(port)
        sock.close()

except socket.gaierror:
    print 'Hostname could not be resolved. Exiting'
    sys.exit()

except socket.error:
    print "Couldn't connect to server"
    sys.exit()

OUTPUT [works]


SOCKET: s3eInetAton: 'virtuhorizon.com'
SOCKET: s3eInetLookup: 'virtuhorizon.com'
SOCKET: s3eInetLookup (synchronous): done DNS: '74.220.219.55:0'
IWCRT: gethostbyname virtuhorizon.com -> 4a700360


>>> Please wait, scanning remote host 74.220.219.55


IWCRT: open 100
SOCKET: s3eSocketCreate -> p=0x00b20eb8 id=3001
IWCRT: connect: 100

SOCKET: s3eSocketConnect: 0x00b20eb8 -> 74.220.219.55 :80

ERROR: S3E_SOCKET_ERR_INPROGRESS in s3eSocketConnect
SOCKET: TryConnect error: 10036
SOCKET: Connect: FAILED (1001: S3E_SOCKET_ERR_INPROGRESS in s3eSocketConnect)
SOCKET: TryConnect error: 10056
SOCKET: NotifyConnect: 3001 0x00b20eb8
IWCRT: got connect result: 0

>>> Port 80:         Open

IWCRT: close 100
SOCKET: s3eSocketClose: 0x00b20eb8 open=1

>>> Scanning Completed in:  0:00:00


Ideas?

  • missing settings in pyconfig?
  • aton / pton support issues?
  • RSIC support issues ( RISCO ? )
  • contact marmalade developers for their s3esocket source ( not gonna happen )
flow
  • 571
  • 1
  • 4
  • 16
  • Hmm Interesting. I have a C++ Marmalade app which has been running 24/7 mostly for months, and today started showing this error too. ("tryconnect error: 10056"). – Dronz Mar 16 '16 at 22:23

0 Answers0