Skip to content

Instantly share code, notes, and snippets.

@amd64bit
Forked from glegoux/udpserver.py
Created April 20, 2018 04:32
Show Gist options
  • Select an option

  • Save amd64bit/aa7210b85b4a1451ed8a1bd82114f56a to your computer and use it in GitHub Desktop.

Select an option

Save amd64bit/aa7210b85b4a1451ed8a1bd82114f56a to your computer and use it in GitHub Desktop.

Revisions

  1. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    UDP_PORT = 8000

    # listen for UDP messages
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    server.bind((UDP_IP_ADDRESS, UDP_PORT))
    print("Serving UDP on {} port {} ...".format(UDP_IP_ADDRESS, UDP_PORT))

  2. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@

    while True:
    data, addr = server.recvfrom(1024)
    print("Message: {}".format(data.decode('utf-8')))
    print("Received message: '{}'".format(data.decode('utf-8')))
  3. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@

    while True:
    data, addr = server.recvfrom(1024)
    print("Message: {}".format(data.decode('utf-8'))
    print("Message: {}".format(data.decode('utf-8')))
  4. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@

    while True:
    data, addr = server.recvfrom(1024)
    print("Message: {}", data)
    print("Message: {}".format(data.decode('utf-8'))
  5. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,11 @@
    #
    # udpserver.py
    #
    # See Gist udpclient.py.
    # See Gist udpclient.py to send a UDP message.
    #
    # Run UDP server on 127.0.0.1 port 8000.
    #
    # usage: python3 udpserver.py

    if __name__ == "__main__":
    import socket
  6. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,8 @@
    # listen for UDP messages
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server.bind((UDP_IP_ADDRESS, UDP_PORT))

    print("Serving UDP on {} port {} ...".format(UDP_IP_ADDRESS, UDP_PORT))

    while True:
    data, addr = server.recvfrom(1024)
    print("Message: {}", data)
  7. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions udpserver.py
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,13 @@
    # See Gist udpclient.py.

    if __name__ == "__main__":

    import socket

    UDP_IP_ADDRESS = "127.0.0.1"
    UDP_PORT = 8000

    # listen for UDP messages
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    UDP_IP_ADDRESS = "127.0.0.1"
    UDP_PORT = 8000
    server.bind((UDP_IP_ADDRESS, UDP_PORT))

    while True:
  8. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions udpserver.py
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,11 @@
    if __name__ == "__main__":

    # listen for UDP messages
    serverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    UDP_IP_ADDRESS = "127.0.0.1"
    UDP_PORT = 8000
    serverSock.bind((UDP_IP_ADDRESS, UDP_PORT))
    server.bind((UDP_IP_ADDRESS, UDP_PORT))

    while True:
    data, addr = serverSock.recvfrom(1024)
    data, addr = server.recvfrom(1024)
    print("Message: {}", data)
  9. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/env bash
    #!/usr/bin/env python3
    #
    # udpserver.py
    #
  10. @glegoux glegoux revised this gist Aug 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udpserver.py
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,4 @@

    while True:
    data, addr = serverSock.recvfrom(1024)
    print "Message: ", data
    print("Message: {}", data)
  11. @glegoux glegoux created this gist Aug 29, 2017.
    17 changes: 17 additions & 0 deletions udpserver.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/usr/bin/env bash
    #
    # udpserver.py
    #
    # See Gist udpclient.py.

    if __name__ == "__main__":

    # listen for UDP messages
    serverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    UDP_IP_ADDRESS = "127.0.0.1"
    UDP_PORT = 8000
    serverSock.bind((UDP_IP_ADDRESS, UDP_PORT))

    while True:
    data, addr = serverSock.recvfrom(1024)
    print "Message: ", data