Skip to content

Instantly share code, notes, and snippets.

@shubham7298
Created August 30, 2018 11:53
Show Gist options
  • Save shubham7298/95a1761c2afa95a13d8c9944b114d5a6 to your computer and use it in GitHub Desktop.
Save shubham7298/95a1761c2afa95a13d8c9944b114d5a6 to your computer and use it in GitHub Desktop.
Socket Programming in Python(server)
# Save as server.py
# Message Receiver
import os
from socket import *
host = ""
port = 13000
buf = 1024
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
print "Waiting to receive messages..."
while True:
(data, addr) = UDPSock.recvfrom(buf)
print "Received message: " + data
if data == "exit":
break
UDPSock.close()
os._exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment