Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
changes to client.py
Browse files Browse the repository at this point in the history
anti plag, and other changes
  • Loading branch information
nishantr05 authored Dec 17, 2020
1 parent 100222f commit 2b4b448
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions client.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
# Import socket module
# Import necessary modules
import socket
import sys
import time

# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Define the port on which you want to connect
port = 12345
ip = '127.0.0.1'
filename = 'test.pdf'
# Creating a socket object 'soc_obj'.
# 'AF_NET'-> Ipv4 addressing, 'SOCK_STREAM'-> for TCP protocol.
soc_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

port, ip = 42420, '127.0.0.1' # Defining port and ip details:
filename = 'test.txt' # test file to send to the server
# connect to the server on local computer
s.connect((ip, port))
print(f"Connected to {ip}:{port}")
s.send(f"{filename}".encode("utf-8"))
try :
soc_obj.connect((ip, port))
print(f"Connected to {ip}:{port}.")
except :
print("Failed to establish connection")
sys.exit()

# sending the test file name,followed by test data
soc_obj.send(f"{filename}".encode("utf-8"))
time.sleep(0.5) # waiting for a short while for server to recieve data
f = open (filename, "rb")
#Sending the data,1KB at a time.
l = f.read(1024)
while (l):
s.send(l)
soc_obj.send(l)
l = f.read(1024)
# close the connection
print(f"{filename} sent")
s.close()
soc_obj.close()

0 comments on commit 2b4b448

Please sign in to comment.