Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket, thread
- def runcon(client, addr):
- global CONNECTION_LIST
- global SOCKET_LIST
- while True:
- try:
- message = client.recv(1024)
- if message == "/list":
- for listip in CONNECTION_LIST:
- client.send(listip)
- else:
- for clientsocket in SOCKET_LIST:
- if clientsocket != client:
- clientsocket.send(message)
- except:
- CONNECTION_LIST.remove(addr[0])
- SOCKET_LIST.remove(client)
- print addr[0], "Closed!"
- break
- if __name__ == '__main__':
- CONNECTION_LIST = []
- SOCKET_LIST = []
- mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- mysocket.bind(("0.0.0.0", 8287))
- mysocket.listen(10)
- while True:
- try:
- client,addr = mysocket.accept()
- except KeyboardInterrupt:
- mysocket.close()
- exit("Socket server closed.")
- print addr[0], "connected!"
- CONNECTION_LIST.append(addr[0])
- SOCKET_LIST.append(client)
- try:
- thread.start_new_thread(runcon,(client,addr,))
- except:
- "Error =>", addr[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement