Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- #INITIAL CONTACT SERVER
- ics_addr = ('', 4760) #any interface, port 4763
- ics = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #tcp socket
- ics.bind(ics_addr) #listen on this address
- ics.listen(5) #backlog, dont mind this
- req2srv = {
- '1': '127.0.0.1:4761', #type 1
- '2': '127.0.0.1:4762', #type 2
- '3': '127.0.0.1:4763', #type 3
- }
- listen = True
- while listen: #accept connections until listen==False
- client, addr = srv.accept() #wait for client to connect
- data = client.recv(1024) #recv 1024 bytes (max, can be less) of data
- if data: #if data==False recv failed
- req_type = data.strip() #strip whitespace from both ends
- srv = req2srv(req_type) #get server address from request type
- client.send(srv) #send client server address
- client.close() #close client socket
- ics.close() #close ics socket
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement