943,645 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 365
  • Python RSS
Feb 1st, 2009
0

Simple server problem

Expand Post »
Hello all. I'm working with pygame and are trying to implement some type of server.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
besktrap is offline Offline
58 posts
since Jul 2008
Feb 1st, 2009
0

Re: Simple server problem

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:

Python Syntax (Toggle Plain Text)
  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':

Python Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
besktrap is offline Offline
58 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Any Idea on Media Player Library/Module
Next Thread in Python Forum Timeline: Using a list as values in a dictionary?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC