Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 22nd, 2011  |  syntax: Python  |  size: 1.08 KB  |  views: 239  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from socket import *
  2. import time, random, thread
  3. Port, Port2, HostIP, myname, mypw, newdata = 50005, 50003, "localhost", "", "", ""
  4.  
  5. def recvloop(soc):
  6.     global newdata
  7.     while 1:
  8.         newdata = soc.recv(1024)
  9.         print newdata
  10.  
  11. def sendloop(soc2):
  12.     while 1:
  13.         soc2.send("hi there")
  14.         time.sleep(2)
  15.        
  16. soc = socket(AF_INET, SOCK_STREAM)
  17. soc.connect((HostIP, Port))
  18. while 1:
  19.     print "only 1 word is taken for each name and password"
  20.     myname = raw_input("Your name please: ")
  21.     myname = myname.split()
  22.     myname = myname[0]
  23.     mypw = raw_input("Your password? ")
  24.     mypw = mypw.split()
  25.     mypw = mypw[0]
  26.     soc.send("%s %s" %(myname, mypw))
  27.     incoming = soc.recv(1024)
  28.     if incoming == "welcome":
  29.         print "welcome, you are online now"
  30.         break
  31.     if incoming == "wrong password":
  32.         print "wrong password or name is taken already"
  33. soc2 = socket(AF_INET, SOCK_STREAM)
  34. soc2.connect((HostIP, Port2))
  35. thread.start_new_thread(recvloop, (soc, ))
  36. thread.start_new_thread(sendloop, (soc2, ))
  37.  
  38.  
  39. while 1:
  40.     pass