Advertisement
Guest User

Untitled

a guest
Jun 24th, 2011
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. from socket import *
  2. import time, random, thread
  3. Port, Port2, HostIP, myname, mypw, newdata = 50005, 50003, "localhost", "", "", ""
  4. gamemode = "lobby"
  5. Clientsonline = []
  6.  
  7. def recvloop(soc):
  8.     global newdata
  9.     while 1:
  10.         newdata = soc.recv(1024)
  11.         newlist = newdata.split()
  12.         newjob = newlist[0]
  13.         newlist.pop(0)
  14.         if newjob == "say":
  15.             newname = newlist[0]
  16.             newlist.pop(0)
  17.             newlist2 = " ".join(newlist)
  18.             print newname, newjob, newlist2
  19.         if newjob == "upd":
  20.             newlist2 = newlist[0]
  21.             Clientsonline = newlist2.split()
  22.             print "Clients online: ", Clientsonline
  23.            
  24.  
  25. def sendloop(soc2):
  26.     while 1:
  27.         inputtxt = raw_input("")
  28.         inputtxt = "say %s" %inputtxt
  29.         soc2.send(inputtxt)
  30.        
  31. soc = socket(AF_INET, SOCK_STREAM)
  32. soc.connect((HostIP, Port))
  33. while 1:
  34.     print "only 1 word is taken for each name and password"
  35.     myname = raw_input("Your name please: ")
  36.     myname = myname.split()
  37.     myname = myname[0]
  38.     mypw = raw_input("Your password? ")
  39.     mypw = mypw.split()
  40.     mypw = mypw[0]
  41.     soc.send("%s %s" %(myname, mypw))
  42.     incoming = soc.recv(1024)
  43.     if incoming == "welcome":
  44.         print "welcome, you are online now"
  45.         break
  46.     if incoming == "wrong password":
  47.         print "wrong password or name is taken already"
  48. soc2 = socket(AF_INET, SOCK_STREAM)
  49. soc2.connect((HostIP, Port2))
  50. thread.start_new_thread(recvloop, (soc, ))
  51. thread.start_new_thread(sendloop, (soc2, ))
  52.  
  53.  
  54. while 1:
  55.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement