Last active
October 30, 2018 06:11
-
-
Save huberflores/6a5ecee3ef4920d16b4c0cb1c737bb6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From socket module we import the required structures and constants. | |
from socket import AF_INET, SOCK_DGRAM, socket | |
if __name__ == '__main__': | |
print 'Application started' | |
# Creating a UDP/IP socket | |
s = socket(AF_INET, SOCK_DGRAM) | |
# Binding the UDP/IP socket to address and port | |
s.bind(('127.0.0.1',7778)) | |
print 'Socket is bound to %s:%d' % s.getsockname() | |
# Receiving the message, maximal payload to receive in one peace | |
recv_buffer_length = 1024 | |
print 'Waiting for message ...' | |
message,source = s.recvfrom(recv_buffer_length) | |
print 'Received message from %s:%d' % source | |
print 'Payload lengh %d bytes: [%s]' % (len(message),message) | |
raw_input('Press Enter to teminate ...') | |
print 'Closing the UDP socket ...' | |
s.close() | |
print 'Terminating ...' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From socket module we import the required structures and constants. | |
from socket import AF_INET, SOCK_DGRAM, socket | |
if __name__ == '__main__': | |
print 'Application started' | |
# Creating a UDP/IP socket | |
s = socket(AF_INET, SOCK_DGRAM) | |
# Binding the UDP/IP socket to address and port | |
s.bind(('127.0.0.1',7777)) | |
print 'Socket is bound to %s:%d' % s.getsockname() | |
# Sending the message | |
message = 'Hell world!' | |
destination = ('127.0.0.1',7778) | |
s.sendto(message,destination) | |
print 'Sent message to %s:%d' % destination | |
print 'Payload lengh %d bytes: [%s]' % (len(message),message) | |
raw_input('Press Enter to teminate ...') | |
print 'Closing the UDP socket ...' | |
s.close() | |
print 'Terminating ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment