Created
January 8, 2021 10:54
-
-
Save cankush625/c8a9b202027d2046147cd819d2a79c1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import threading | |
# Using IPv4 and UDP protocol | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
ip = input("Enter your IP address: ") | |
port = int(input("Enter your port: ")) | |
# Creating socket | |
s.bind((ip, port)) | |
recvIP = input("Enter the IP of the receiver: ") | |
recvPort = int(input("Enter the port of the receiver: ")) | |
# Function for receiving messages | |
def receiveMessages(): | |
while(True): | |
data = s.recvfrom(1024) | |
data = data[0].decode() | |
print(f'\nReceived message: {data}') | |
# Function for sending messages | |
def sendMessages(): | |
while(True): | |
message = input("Enter the message: ") | |
s.sendto(message.encode(), (recvIP, recvPort)) | |
receive = threading.Thread(target=receiveMessages) | |
send = threading.Thread(target=sendMessages) | |
receive.start() | |
send.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment