#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Very Quick Question


    In VB6 when using the Winsock control you need to use a DataArrival. Is this (anything like this) needed in Python?I also have 1 more question, does Python have a function like the VB6 function, CLng()?
  2. #2
  3. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,805
    Rep Power
    1570
    For the first question, I must confess that I do not know enough of how either VB or Python handle sockets to give a direct answer. However, you might want to check this Python sockets tutorial for some information. My impression is that you generally would not call Winsock directly, but would use the standard (and portable) sockets library that comes with the language distro.

    For the second question, can you give the context of the typecast in question? Chances are, you won't need ot at all, as Python integers are the same size as VB Longs already, and using a Python long would probably be inappropriate.
    Last edited by Schol-R-LEA; December 13th, 2004 at 09:16 PM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Here is an example, (I'm still working on the code, it's half vb, half python)

    GTC = Val("&H" & StrToHex(StrReverse(data[8:4])))
    GTC = CLng(GTC)
  6. #4
  7. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,805
    Rep Power
    1570
    OK, that's a bit funny... it converts the integer-value string to a long and then back to a string? I guess they needed to make sure it was extended to 32-bits or something.

    Anyway, this should be necessary in your new code, as Python integers are already 32 bits wide. You can drop that line outright.

    Oh, and here is a working Sockets demo in Python:
    Code:
    import socket
    
    # The address of the web host and the page to fetch.
    # These can be set to other web hosts and pages;
    # i.e., "www.python.org" and "/doc/2.4/"
    host = "localhost"
    page = "/index.html"
    
    #create an INET, STREAMing socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    #now connect to the web server on port 80 
    # - the normal http port
    s.connect((host, 80)) 
    
    # Send a simple request header for the page
    s.send("GET ")
    s.send(page)
    s.send(" HTTP/1.0\n")
    s.send("From: someone@somewhere.org\n")
    s.send("User-Agent: PyHTTPSockDemo\n\n")
    
    # read in the page until the socket connection is broken
    msg = ''
    chunk = '  '
    while chunk != '':
    	chunk = s.recv(1)
    	msg = msg + chunk
    	
    # print the gathered message string w/out parsing it
    print msg
    This will connect to a web server, fetch a web page, and print out the returned headers followed by the raw HTML source for the page. This was modified from the code in the Sockets tutorial listed above, plus information found on the "HTTP Made Really Easy" page. HTH.
    Last edited by Schol-R-LEA; December 14th, 2004 at 12:19 AM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Wait which line so I drop out, the CLng() 1? Also, when connecting through a socket, won't s = socket(AF_INET,SOCK_STREAM) work as well?

IMN logo majestic logo threadwatch logo seochat tools logo