Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import socket
  2. import time
  3.  
  4. def messageStream():
  5.     while True:
  6.         incommingMessages = c.recv(1024)
  7.         print incommingMessages
  8.         for client in clients:
  9.             c.send(incommingMessages)
  10.  
  11.  
  12. print "Loading..."
  13. host = '0.0.0.0'
  14. port = 4998
  15. print str(host) + ":" + str(port)
  16.  
  17.  
  18.  
  19. s = socket.socket() #Creates a socket object
  20. s.bind((host,port)) #Binds the IP to the Port
  21. s.listen(10) #Listens for incomming TCP Connections
  22.  
  23. print "Server Online" #server is now online and listening
  24.  
  25. while 1:
  26.     clients = []
  27.     c, addr = s.accept() #if detected, accepts the connection
  28.     print "<" + time.ctime() + ">" + " Connection from: " + str(addr) #print that a client connected
  29.     if addr not in clients: #If that client's IP doesn't exist in the clients list, add it
  30.         clients.append(addr)
  31.         c.send("Connection Successful! Welcome <3")
  32.     try:
  33.         incommingMessage= c.recv(1024)
  34.         print "<" + time.ctime() + ">" + " From " + str(addr) + ": " + str(incommingMessage)
  35.         for client in clients:
  36.             print "send"
  37.             s.send(incommingMessage, client)
  38.     except:
  39.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement