Compare commits

..

No commits in common. "dd241b9e516e40fc92f1d837d04dc96bbb519078" and "0ffed4495862f0ddc12afaf7f0500e873f1bbd88" have entirely different histories.

4 changed files with 0 additions and 61 deletions

View File

@ -1,28 +0,0 @@
import socket
def receive_file(port):
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', port))
print(f"Listening for incoming files on port {port}...")
# Receive file information
data, addr = sock.recvfrom(1024)
filename, filesize = data.decode().split(":")
filesize = int(filesize)
with open(filename, "wb") as f:
print(f"Receiving {filename}...")
bytes_received = 0
while bytes_received < filesize:
data, addr = sock.recvfrom(1024) # Receive in chunks
f.write(data)
bytes_received += len(data)
print(f"File {filename} received successfully.")
sock.close()
if __name__ == "__main__":
port = int(input("Enter the port to listen on: "))
receive_file(port)

View File

@ -1,30 +0,0 @@
import socket
import os
def send_file(filename, host, port):
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Get file size
filesize = os.path.getsize(filename)
sock.sendto(f"{filename}:{filesize}".encode(), (host, port))
with open(filename, "rb") as f:
print(f"Sending {filename}...")
bytes_sent = 0
while bytes_sent < filesize:
data = f.read(1024) # Read in chunks
sock.sendto(data, (host, port))
bytes_sent += len(data)
print(f"File {filename} sent successfully.")
sock.close()
if __name__ == "__main__":
target_host = input("Enter the receiver's IP address: ")
target_port = int(input("Enter the receiver's port: "))
# Choose a file to send
filename = input("Enter the file path to send (Text, Audio, Video, or Script): ")
send_file(filename, target_host, target_port)

Binary file not shown.

View File

@ -62,11 +62,8 @@ This Git repository is a comprehensive resource for the Computer Networks and Se
- [Output-B8](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-B8.pdf)
##### B9 - UDP Protocol
- [Code-B9 (Sender)](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B9%20%28Sender%29.py)
- [Code-B9 (Receiver)](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-B8%20%28Receiver%29.py)
- [Handout-B9](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Handouts/Handout-B9.pdf)
- [Write-up - B9](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Write-ups/Write-up%20-%20B9.pdf)
- [Output-B9](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-B9.pdf)
##### C10 - DNS
- [Handout-C10](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Handouts/Handout-C10.pdf)