December 13th, 2004, 07:00 PM
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()?
December 13th, 2004, 08:33 PM
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.
December 13th, 2004, 09:18 PM
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)
December 14th, 2004, 12:05 AM
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:
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.
# 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
# Send a simple request header for the page
# 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
Last edited by Schol-R-LEA; December 14th, 2004 at 12:19 AM.
December 14th, 2004, 01:56 PM
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?