old_contents: #!/usr/bin/env python
  
  import socket
  
  #Create which contains all the servers and maps they are running. This string is then send to clients.
  def createServerList(serverList):
    ser_string = ""
    for server in serverList:
      ser_string = ser_string + server[0] + " " + server[1] + "\200"
    return ser_string
  
  def getOwnAddr():
    #We're creating connection to google server, to find out our own IP
    googleAddr = socket.getaddrinfo('8.8.8.8', 53)
    #googleAddr = socket.getaddrinfo('www.google.fi', 80)
    #Choose last tuple from the received list of addresses to get an IPv4 connection
    googleAddr = googleAddr[-1][-1]
    #print "Connecting to google server:", googleAddr
    #Connect to google server
    try:
      ownAddr = socket.create_connection(googleAddr, 5)
      #Retrieve own IP
      my_IP = ownAddr.getsockname()[0]
      ownAddr.close()
      print "Retrieved own IP: ", my_IP
    except socket.timeout:
      print "No connection, creating localserver"
      my_IP = 'localhost'
    return my_IP
    
  def main():
  
    my_IP = getOwnAddr()
    port = 3500
    #serverAddr = "M4 127.0.0.1 4375"
    clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #All servers that have announced themselves are added to this list:
    serverList = []
    
    #Look for open port:
    while True:
      try:
        clientSocket.bind((my_IP, port))
        break
      except socket.error:
        port += 1
  
      
    
    print "Listening for connection on: ", clientSocket.getsockname()
    #print "Redirection message: ", serverAddr
    
    clientSocket.listen(10)
    
    while 1:
    
      (client, addr) = clientSocket.accept()
      recv = client.recv(1024)
      if recv[0] == 'H':
        print "Client connected from: ", addr
        print "Responding with serverlist of %d servers" % len(serverList)
        sendMe = createServerList(serverList)
        sendMe = "L%x " % (len(serverList)) + sendMe
        #sendMe = "L{:02X} ".format(len(serverList)) + sendMe
        client.send(sendMe);
      elif recv[0] == 'S':
        print "Map server connected: ", addr
        client.send("O");
        # Close this connection as soon as possible:
        client.close()
        addrString = addr[0] + " " + str(addr[1])
        serverList.append([addrString, chr(ord(recv[1])+48)])
        print "Added: ", serverList[-1]
        print "Serverlist is now %d long" % len(serverList)
      else:
        print "Got unexpected message from client: %s msg: %s" % (addr, recv)
  
      client.close()
  
  if __name__ == "__main__":
    main()
  
new_contents: #!/usr/bin/env python
  
  import socket
  
  #Create which contains all the servers and maps they are running. This string is then send to clients.
  def createServerList(serverList):
    ser_string = ""
    for server in serverList:
      ser_string = ser_string + server[0] + " " + server[1] + "\200"
    return ser_string
  
  def getOwnAddr():
    #Connect to google server
    try:
      ownAddr = socket.create_connection(('8.8.8.8', 53), 5)
      #Retrieve own IP
      my_IP = ownAddr.getsockname()[0]
      ownAddr.close()
      print "Retrieved own IP: ", my_IP
    except socket.timeout:
      print "No connection, creating localserver"
      my_IP = 'localhost'
    return my_IP
    
  def main():
  
    my_IP = getOwnAddr()
    port = 3500
    clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #All servers that have announced themselves are added to this list:
    serverList = []
    
    #Look for open port:
    while True:
      try:
        clientSocket.bind((my_IP, port))
        break
      except socket.error:
        port += 1
  
    print "Listening for connection on: ", clientSocket.getsockname()
    #print "Redirection message: ", serverAddr
    
    clientSocket.listen(10)
    
    while 1:
    
      (client, addr) = clientSocket.accept()
      recv = client.recv(1024)
      if recv[0] == 'H':
        print "Client connected from: ", addr
        print "Responding with serverlist of %d servers" % len(serverList)
        sendMe = createServerList(serverList)
        sendMe = "L%x " % (len(serverList)) + sendMe
        #sendMe = "L{:02X} ".format(len(serverList)) + sendMe
        client.send(sendMe);
      elif recv[0] == 'S':
        print "Map server connected: ", addr
        client.send("O");
        # Close this connection as soon as possible:
        client.close()
        addrString = addr[0] + " " + str(addr[1])
        serverList.append([addrString, chr(ord(recv[1])+48)])
        print "Added: ", serverList[-1]
        print "Serverlist is now %d long" % len(serverList)
      else:
        print "Got unexpected message from client: %s msg: %s" % (addr, recv)
  
      client.close()
  
  if __name__ == "__main__":
    main()
  
subject: Connect straight to the IP