Created
October 31, 2019 00:41
-
-
Save pratikpc/0a2692b1dfbe2a27b0c4bfed0eb6c236 to your computer and use it in GitHub Desktop.
UDP Client and Server using Python
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
def ToStr(string): | |
return str(string)[2:-1] | |
import socket | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client: | |
client.connect(('localhost', 9000)) | |
string = 'ABCBA' | |
client.sendall(bytes(string, 'utf-8')) |
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
import socket | |
def ToStr(string): | |
return str(string)[2:-1] | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server: | |
server.bind(('localhost', 9000)) | |
while True: | |
string = ToStr(server.recv(1024)) | |
reversed = string[::-1] | |
print(string, reversed) | |
if reversed == string: | |
print(string, "is palindrome") | |
else: | |
print(string, "is not palindrome") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment