title: Basic UDP & TCP Program
body: <p>I am trying to write a simple server that will listen for one set of messages on UDP and another set of messages on TCP. I have written the following code:</p>
  
  <pre><code>from threading import Thread
  import time
  import socket 
  
  #define UDP listening function
  def UDPListen():
      Listening_UDP_Port = 300
      Listening_IP = "127.0.0.1"
      BUFFER_SIZE = 64
  
      sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # IPv4, UDP
      sock.bind((Listening_IP, Listening_UDP_Port))
  
      while True:
          data, address = sock.recvfrom(BUFFER_SIZE)
          print "UDP Messsage from address: ", address
          print "Message: ", data
  
  # END UPDListen() FUCNTION
  
  
  #define a TCP listening function
  def TCPListen():
      Listening_TCP_Port = 300
      Listening_IP = "127.0.0.1"
      BUFFER_SIZE = 64
  
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # IPv4, TCP
      sock.bind((Listening_IP, Listening_TCP_Port))
  
      while True:
          sock.listen(1)
          conn, address = sock.accept()
          print "TCP connection from", address
          data = conn.recv(BUFFER_SIZE)
          print "Mesage: ", data
          conn.close()
  
  # END TCPListen() FUCNTION
  
  
  # main function
  def main():
      ThreadUDP = Thread(target=UDPListen)
      ThreadTCP = Thread(target=TCPListen)
  
      print "Starting Server..."
      ThreadUDP.start()
      ThreadTCP.start()
      print "Server Started!"
  
  #END main() FUNCTION
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>However when I run it in Python 2.7 it throws a wobbly, any ideas where I am going wrong?</p>