Simple server problem

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 58
Reputation: besktrap is an unknown quantity at this point 
Solved Threads: 1
besktrap's Avatar
besktrap besktrap is offline Offline
Junior Poster in Training

Simple server problem

 
0
  #1
Feb 1st, 2009
Hello all. I'm working with pygame and are trying to implement some type of server.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 58
Reputation: besktrap is an unknown quantity at this point 
Solved Threads: 1
besktrap's Avatar
besktrap besktrap is offline Offline
Junior Poster in Training

Re: Simple server problem

 
0
  #2
Feb 1st, 2009
oops! sorry. anyways...

i'm a little fuzzy on all this socket server stuff, so try to bear with me. I want to users to be able to connect to each other. the code for my server is:

  1. import socket
  2.  
  3. socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4. socket.bind(( "", 1024 ))
  5. print "Bind socket to: 1024..."
  6. socket.listen(2) # Listen for connections made to the socket; can support 2, as we specified
  7. conn, addr = socket.accept() # accepts connection
  8.  
  9. while 1: # infinite while loop
  10. print 'Running?'
  11. data = conn.recv(1024)
  12. if not data:
  13. break
  14. conn.send(data)

and for my 'client':

  1. import socket
  2.  
  3. socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4. socket.connect(1024)
  5. os.system("pause")

so how does a server really work? mine doesn't really work when I run it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 289 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC