testing client-server sockets

David Harrison dave.l.harrison at gmail.com
Fri Apr 18 11:27:21 CEST 2008


On 18/04/2008, Astan Chee <stanc at al.com.au> wrote:
>  Server code:
>
>  import os, sys, socket
>  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>  host = ''
>  port = 5602
>  s.bind((host,port))
>  try:
>      s.listen(1)
>      while 1:
>          conn, addr = s.accept()
>          print 'client is at', addr
>          data = conn.recv(1000000)
>          data = data * 10
>          z = raw_input()
>          conn.send(data)
>          conn.close()
>  except Exception:
>      s.close()
>
>  Client code:
>
>  import sys, os, socket
>
>              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>              host = 'hostIP'
>              port = 5602
>              s.connect((host,port))
>              s.send(dlg.user.GetValue())
>              i =0
>              while True:
>                  data = s.recv(1000000)
>                  i+=1
>                  if (i<5):
>                      print data
>                  if not data:
>                      break
>                  print 'received', len(data), 'bytes'
>              s.close()

I just ran the code (albeit with a tiny change to send a small string
instead so I could see what was going on), and it seems to work fine
... anything else that might be different ?



More information about the Python-list mailing list