0% found this document useful (0 votes)
12 views26 pages

cn record

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views26 pages

cn record

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

RAJIV GANDHI ARTS AND SCIENCE COLLEGE

THAVALAKUPPAM
PUDUCHERRY – 605 007

DEPARTMENT OF
COMPUTER APPLICATIONS
Bachelor of Computer Applications - Third Semester
2023-2024
Record Note Book
MAIN PRACTICAL
COMPUTER NETWORK LAB
Name :

Reg.No :
RAJIV GANDHI ARTS AND SCIENCE COLLEGE
THAVALAKUPPAM – PUDUCHERRY – 605 007
DEPARTMENT OF COMPUTER APPLICATIONS
BONAFIDE CERTIFICATE
Certified that this is a bonafide record of practical work

done by Mr./Ms..........................................p................

Reg.No......................

In COMPUTER N E T W O R K S LAB (CSCA238), Third

Semester of BCA, Degree Course in the Department of Computer

Applications during the year 2023-2024

Staff In-charge Head of the


Department
Submitted for the University Examination held on......................

at Rajiv Gandhi Arts and Science College, Thavalakkuppam,

Puducherry.

Internal Examiner External Examiner


TEACHER
S.N0 DATE CONTENT PAGE SIGNATURE
NO

01

02

03

04

05

06

07
GET IP USING SOCKET

PROGRAM

import socket
system=socket.gethostname()
ip_address=socket. gethostbyname(system)
print ("ip address is"+ip_address)
OUTPUT:
ONE WAY CONNECTION USING TCP

CLIENT PROGRAM

import socket

sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4444

print("waiting for server accept the connection...")

sock_connect=sock.connect((host,port))

print("connected")

while True:

try:

data=sock.recv(1024)

print(data.decode('utf-8'))

except Exception as e:

print("you are disconnected")

break

sock.close()
OUTPUT:
SERVER PROGRAM

import socket

sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4444

sock.bind((host,port))

print("waiting for connection...")

sock.listen(1)

conn,address=sock.accept()

print("connected to "+address[0])

while True:

try:

connection=conn.fileno()

if connection == -1:

print("client disconnected")

break

data=input("enter the message: ")

byte_data=data.encode("utf-8")

conn.send(byte_data)

except Exception as e:

print("error as occurd")

break

sock.close()
TWO WAY CONNECTION USING TCP

CLIENT PROGRAM

import socket

print("welcome to two way communication using Tcp")

sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

hostname=socket.gethostname()

host=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4848

user_name=input("enter your name: ")

print("waiting for output the connection ")

sock.connect((host,port))

sock.send(user_name.encode('utf-8'))

server_name=sock.recv(1024)

print(user_name+"you are connected to"+server_name.decode('utf-8'))

while True:

data=sock.recv(1024)

print(server_name.decode('utf-8')+">"+data.decode('utf-8'))

message=input(user_name+">")

sock.send(message.encode('utf-8'))

sock.close()
OUTPUT:
SERVER PROGRAM

import socket

print("welocome to two way communication using TCP")

sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4848

user_name=input("enter your name: ")

sock.bind((host,port))

print("waiting for connection..")

sock.listen(2)

conn,addr=sock.accept()

conn.send(user_name.encode('utf-8'))

client_name=conn.recv(1024)

print(user_name+"you are connected to "+client_name.decode('utf-8'))

while True:

message=input(user_name+">")

conn.send(message.encode('utf-8'))

data=conn.recv(1024)

print(client_name.decode('utf-8')+">"+str(data.decode('utf-8')))

sock.close()
OUTPUT:
ONE WAY CONNECTION USING UDP

CLIENT PROGRAM:

import socket

sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4444

print("waiting for accept the connection...")

sock.sendto("connect".encode('utf-8'),(host,port))

print("connected")

while True:

data=sock.recv(1024)

print(data.decode('utf-8'))

if not data:

break

sock.close()
OUTPUT:
SERVER PROGRAM

import socket

sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4444

print("waiting for new connection...")

sock.bind((host,port))

data=sock.recvfrom(1024)

print(data)

print("connected")

while True:

try:

message=input("enter message to send: ")

sock.sendto(message.encode('utf-8'),data[1])

except Exception as e:

print("Error occurded")

break

sock.close()
OUTPUT:
TWO WAY CONNECTION USING UDP

CLIENT PROGRAM

import socket

sock-socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

hostname-socket.gethostname()

host-socket.gethostbyname(hostname)

port-4444

print("Waiting for accept the connection....")

sock.sendto("connect".encode('utf-8'), (host,port))

print("connected")

while True:

data=sock.recvfrom(1024)

print(data[0].decode('utf-8'))

message=input("Enter the message to send:")

sock.sendto(message.encode('utf-8'),data[1])

if not data:

break

sock.close()
SERVER PROGRAM

import socket

sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

hostname=socket.gethostname()

host-socket.gethostbyname(hostname)

port=4444

print("Waiting for new connection....")

sock.bind((host,port))

print("connected")

while True:

try:

data-sock.recvfrom(1024)

print(data[0].decode('utf-8'))

message=input("Enter message to sends)

sock.sendto(message.encode('utf-8'),data[1])

except Exception as e:

print("An error as occured")

break

sock.close()
OUTPUT:
URL PARSE

from urllib import parse

url-parse.urlparse('http://google.com:80/gmail')

scheme=url.scheme

port=url.port

location-url.netloc

neturl=url.geturl()

print(scheme)

print(port)

print(location)

print(neturl)
OUTPUT:
FILE SHARING

CLIENT PROGRAM

import socket

sock-socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname socket.gethostname()

host-socket.gethostbyname(hostname)

port-4444

sock.connect((host,port))

print("connected")

while True:

data-sock.recv(1024)

with open("THE EGAL IS COMMING.txt'wb') as f:

f.write(data)

f.close()

print("File Saved")

sock.close()
OUTPUT:
SERVER PROGRAM

import socket

sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname=socket.gethostname()

host=socket.gethostbyname(hostname)

port=4444

sock.bind((host,port))

sock.listen(10)

conn,addr=sock.accept()

print("connected")

print("Sending Filess...")

with open('text.txt', 'rb') as f:

file=f.read(860160)

conn.send(file)

f.close()

sock. close()
OUTPUT :

You might also like