Python Socket programming

Created on Oct 14, 2013

@author: ishaansutaria
import socket #for sockets

#Creates a UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#You can use bind to use a socket number. But it is not required.
#if you do not use this statement then it will bind to a port that is available
s.bind((“”, 44444))
#Server address
host = ‘’;
#Port on which you want to send the packet
port = 55056;
msg = ‘This is the message being sent in the udp packet’

#Send the packet
s.sendto(j, (host, port))
print “message sent”

#Receiving Message
while 1 == 1:
d = s.recvfrom(1024)
print d


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s