Sockets: code works locally but fails over LAN

n00m n00m at
Sun Sep 4 15:41:53 CEST 2005

Bryan Olson wrote:
> Ah, yes, I see. (In my defense, I had already fixed that bug in
> my second version.)
Yes! I myself noticed that, but your 2nd version looks
a bit more verbose.
This all means... what? ONLY send() vs sendall() matters?
Sometimes send() really sends ALL and my version works too!
I must give it a thorough testing!
See how it looks in SQL Server Profiler (it's its utility for
tracing client/server events) WHEN I started 5 copies of .vbs.

Btw, without s2.shutdown(1) those vbs' do NOT disconnect from
the server (see DISCONNECT events on the gif).

The latest python version:
import socket, thread

sqls_host, sqls_port = '', 1433
proxy_host, proxy_port = '', 1434

# How I tested it:
# sqls_host, sqls_port = '', 80

def VB_SCRIPT(s2, cn):
     while 1:
         data = cn.recv(4096)
         if not data:
         print 'VB_SCRIPT:' + data + '\n'

def SQL_SERVER(s2, cn):
     while 1:
         data = s2.recv(4096)
         if not data: return
         print 'SQL_SERVER:' + data + '\n'

s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.bind((proxy_host, proxy_port))

while 1:
     cn, addr = s1.accept()
     s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s2.connect((sqls_host, sqls_port))
     thread.start_new_thread(VB_SCRIPT,(s2, cn))
     thread.start_new_thread(SQL_SERVER,(s2, cn))

The vbs text:
Set cn = CreateObject("ADODB.Connection")
cn.Open _
"Provider=sqloledb;Data Source=,1434;" & _
"Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
"User ID=qwe;Password=asdasd;"
cn.Execute _
"select 'AAAAAAAAAAAAAAA';" & _
"waitfor delay '00:00:02'; raiserror('XXX',10,1) with nowait;" & _
"waitfor delay '00:00:02'; raiserror('YYY',10,1) with nowait;" & _
"waitfor delay '00:00:02'; raiserror('ZZZ',10,1) with nowait;" & _
Set cn = Nothing

More information about the Python-list mailing list