Re: Sockets: code works locally but fails over LAN



Bryan;
Look at how I corrected your the very first version
(see added arguments in both functions). And now it
really can handle multiple connections!


import socket, thread

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

# How I tested it:
# sqls_host, sqls_port = 'www.google.com', 80

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

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

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

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))


Without these corrections I got these error messages
when I launched SIMULTANEOUSLY 3 instances of my.vbs:


Unhandled exception in thread started by
Unhandled exception in thread started by
Traceback (most recent call last):
Traceback (most recent call last):
File "D:\Python23\00\socket_Br10.py", line 18, in SQL_SERVER
File "D:\Python23\00\socket_Br10.py", line 13, in VB_SCRIPT
data = s2.recv(4096)
s2.sendall(data)
socket File "<string>", line 1, in sendall
..socketerror.: error: (10054, 'Connection reset by peer')
(10054, 'Connection reset by peer')

.



Relevant Pages

  • Re: fc2, ssh client/server, kernel 494
    ... Error = Connection reset by peer ... closed connection to service sharename$ ...
    (linux.redhat.misc)
  • What does it mean ?????
    ... Oct 20 13:41:09 constellation smbd: getpeername failed. ... Connection reset by peer ... writing 4 bytes to socket 5: ERRNO = Connection reset by peer ...
    (Fedora)
  • Minimizing Connection reset by peer exceptions
    ... This may be more of a socket question than a python question; ... (10054, 'Connection reset by peer') ... Are there any settings that make the 'Connection reset by ...
    (comp.lang.python)
  • Message sent?
    ... corrections. ... Yesterday I had problems with the firewall which closed ... the connection to OE, symantec gave me a message that the ...
    (microsoft.public.internet.mail)
  • Re: Minimizing Connection reset by peer exceptions
    ... (10054, 'Connection reset by peer') ... Generally this just means the connection has closed through some ... Do note, though, that if you aren't using some means of handling the connections asynchronously then your server will normally only queue a very limited number of connections. ...
    (comp.lang.python)