Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
16 views
10 pages
Part 7
cn lab 8
Uploaded by
Danish Raj
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save part7 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
16 views
10 pages
Part 7
cn lab 8
Uploaded by
Danish Raj
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save part7 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save part7 For Later
You are on page 1
/ 10
Search
Fullscreen
OUTPUT: SERVER: RCO er ne tae Sree rere) ‘ a maneeeween Tee ethan tie rity mete toe ste RO Teer et enc terea Sees Ceeer rere Enter the nessage Taipan Sree Enter the nessage... we elon rere Soest Ce ee CLIENT: Cee eee eer java uses or overrides a d Poetic mes Ear maectte cs RESULT: Thus the program was executed and output is verified successfully.c. File Transfer include
include
include
include
Hinclude
include
include
include
include
include
int main (void) ‘ int sockfd = 0; int bytesReceived = 0; char recvBuff(256]; memset (recvBuff, '0', sizeof (recvBuft)); struct sockaddr in serv_addr; /* Create a socket first +/ L£((sockfd = socket(AF_INET, SOCK STREAM, 0))< 0) t print£("\n Error : Could not create socket \n' return 1; 1 /* initialize sockaddr in data structure +/ serv_addr.sin family = AF_Iuet; servladdr.sin port = htons (5000); // port sery_addr.sin_addz.s addr = inet_addr("127.0.0.1"} /* Attempt a connection */ if(connect (sockfd, (struct sockaddr *)sserv_addr, sizeof (serv_addr))<0) t print£("\n Error : Connect Failed \n"); return 1; } f* Create file where data will be stored */ ELLE *£p; fp = fopen("sample_file.tat™, “ab"); LE(NULL == £p) t printf("Error opening file"); return 1; 1 /* Receive data in chunks of 256 bytes */ while |(bytesReceived = read(sockfd, recvBuff, 256)) > 0) { printf ("Bytes received %d\n",bytesReceived) ; 77 vecvBuff{nl = 07 furite(recvBuff, 1,bytesReceived, fp) 7// printt ("ts \n", recvBufe); ) if (bytesReceived < 0) ( printé("\n Read Error \n"); ’ return 0; ’ Server: Hinclude
#include
#include
Hinclude
Hinclude
#include
#include
#include
#include
int main (void) ( int listenta int connfd = 0; struct sockaddr_in serv_addrs char sendBuf£(1025]; int numrv; oF Jistenfd = socket (AF_INET, SOCK STREAM, 0); printf ("Socket retrieve success\n"); memset (éserv_addr, '0', sizeofiserv_addr}); memset (sendBuff, '0', sizeof (sendBuft)); serv_addr.sin_family = AF_INET? serv_addr.sin_addr.8_addr = htonl (TNADDR_ANY) serv_addr.sin port = htons (5000); bind(listenfd, (struct sockaddr*) éserv_addr, sizeof (serv_addr)}; if(listen(listenfd, 10) == -1) ( print£("Failed to listen\n"); return -1; while (1) ( connfd = accept (listenfd, [struct sockaddr*)NULL ,NULL) + /* Open the file that we wish to transfer */FILE *fp = fopen("sample_file.txt","cb"); Lf (Ep==NULL) ( printf ("File opern error"); return 17 /* Read data from file and send it “/ while (1) ( /* Birst read file in chunks of 256 bytes */ unsigned char buff[256)=(0}; int nread = fread (buff, 1,256, fp) + printf ("Bytes read $d \n", nreadh; /* If read was success, send data. */ if(nzead > 0) ‘ printé ("Sending \n"); write(connfd, buff, nread); } if (nread < 256) ‘ if (feof (fp)) printé("End of file\n"); if (ferror (fp) ) printf("Error reading\n")+ break; ) close (connid) ; sleep(1)7 return 0;9. Applications using TCP and UDP Sockets like 4. DNS AIM: IMPLEMENTATION OF SIMPLE DNS To write a UDP program for implementing the simple DNS service. ALGORITHM: UDP Echo Server PNPeAEN Include necessary header files to support functions for Socket definitions Socket types, Internet ‘addresses,l/O functions,UNIX system calls, Declare variables for Socket ID,Port number, Socket addresses,Character buffer etc. Create socket for server. Bind socket with addresses, ‘Specify number of allowed connections, Retrieve information from Connected Socket. Echo retrieved information to Connected Socket, Close Connected Socket. UDP Echo Client Noes eN Include necessary header files to support functions for Socket defini addresses,l/O functions, UNIX system calls, Declare variables for Socket ID,Port number, Socket addresses Character buffer ete, Create socket for alien. Connect client socket to the server socket addresses. Give message to be echoed. Retrieve echoed information from server and display it. Close the Socket, ns, Socket types, InternetSERVER PROGRAM import java.net"; import java i class pisender{ public static void main(String argsf) throws Exception { byle senderBuffer(] = new byte(128); 1 Packets 128 bytes long String toName, userin; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket senderSocket = new DatagramSocket(999); 11 Create socket for sending it (args.length > 0) toName = aras{O}; IP of DNS from command line else toName = "localhost while (userin=in.teadLined)!=null , 1 Read standard input senderBuffer-userin getBytes); J Convert from string to byte array 1/ Send datagram packet out socket senderSocket, send(new DatagramPacket( senderBuffer, senderBuffer.length, InetAddress.getByName(toName), 666);CLIENT PROGRAM Import java.net"; class ptreceiver { Public static void main(String args[) throws Exception { byte receiveDatal] = new bytel1 28}; DatagramSooket receiveSooket = new DatagramSocket(666); _// Create socket for receiving DatagramPacket receivePacket = new DatagramPacket(receiveData, 128); while (true) { receiveSocket.receive(receivePacket); Wait for datagram packet to arrive 1 Print packet contents as String ‘System.out.printin(new String (receivePacket.getData(, 0, receivePacket.getLength()); nouTPUT: SERVER Ee eons Cen SCC Coe Uy Nlabprogran>java pisender localhost
struct y_hiat_entry *elm, *elm2; int num_later = 1; elm = STAILQ FIRST (ar hist_}; while (elm I= NULL 6S num_Tater <- num_dup_acks_) um_later; elm = STATL NEXT(elm, linfo ); ) £ (elm != NULL) { elm ~ findDataPacketInRecvil story (STAILG_NEXT (elm, 2info_) if (elm != NULL) ( elm2 = STATLG_NEXT(eIm, Linfo_}; while (elm2 != NOLL) f (elm2->seq_num_ < seq_num 66 elm2->t_recv ime) ( STATLO_REMOVE (@r_hist_,elm2,r_hist_entry,linfo_}delete eim2; } else elm = eln2; elm2 = STAILG_NEXT(eIm, linfo_): ) ) void DCCPYERCAgent: :removeAcksReevistory ) { struct © hist entry *elml = STAILO FIRST (ér hist); stzuct F hist entry *elm2; int num later = 1; while (elm! != NULL ¢& num later om Lats simi = STAILQ NEXT (etm, Linfo_); num_dup_acks_){ ) if (elm == NULL) return; elma = STAILG_NEXT(eImL, info); while(elm2 != NULL) { Af (elm2->type_ == DCCP_ACK) ( STATLG REMOVE (ar _hist_,eln2,r_hist_entry,linfo_}s delete elma; ) else ( elm] = elma; ) elma = STATIO NEXT(e1m1, Linfo_); inline : hist_eatry SDCCPTREAgent#:findDataPackstInRecvilistory(r hist entry *start) ( while(start != NULL && start->type_ == DCCP_ACK) start = STAILQ NEXT(start, [info ); return starts )
You might also like
CN Lab Manual
PDF
No ratings yet
CN Lab Manual
40 pages
NP Lab
PDF
100% (1)
NP Lab
17 pages
LAB Exercises
PDF
No ratings yet
LAB Exercises
23 pages
Simulation of Data Transfer Using TCP With Loss
PDF
No ratings yet
Simulation of Data Transfer Using TCP With Loss
5 pages
Cs 2307 Network Lab Final Manual
PDF
100% (1)
Cs 2307 Network Lab Final Manual
83 pages
CN Lab
PDF
No ratings yet
CN Lab
21 pages
Rajkiya Engineering College Kannauj: Practical File
PDF
No ratings yet
Rajkiya Engineering College Kannauj: Practical File
17 pages
CS8581 Networks Laboratory 2017
PDF
No ratings yet
CS8581 Networks Laboratory 2017
28 pages
Week-4 Lab Sheet UDP Sockets and File Transfer
PDF
No ratings yet
Week-4 Lab Sheet UDP Sockets and File Transfer
9 pages
Cnfile Complete
PDF
No ratings yet
Cnfile Complete
103 pages
Network Programming Lab: Submit by Guided by
PDF
No ratings yet
Network Programming Lab: Submit by Guided by
28 pages
Networks Laboratory (06CSL77) : Dept. of CSE, NHCE Aug-Nov 2012
PDF
No ratings yet
Networks Laboratory (06CSL77) : Dept. of CSE, NHCE Aug-Nov 2012
20 pages
CN Assignment
PDF
No ratings yet
CN Assignment
18 pages
Simulation of Data Transfer Using TCP Without Loss: Server
PDF
No ratings yet
Simulation of Data Transfer Using TCP Without Loss: Server
4 pages
LAB Manual: Disributed System Name:-Akshay Kumar Sem.: - 7
PDF
No ratings yet
LAB Manual: Disributed System Name:-Akshay Kumar Sem.: - 7
10 pages
CN Record
PDF
No ratings yet
CN Record
75 pages
Computer Network Lab Manual
PDF
No ratings yet
Computer Network Lab Manual
59 pages
Computer Network File
PDF
No ratings yet
Computer Network File
17 pages
CNS Assignment 8
PDF
No ratings yet
CNS Assignment 8
4 pages
Computer Networks Lab Manual
PDF
No ratings yet
Computer Networks Lab Manual
26 pages
CS 3591 Networks Lab Manual - Updated Oct - 18 (2024)
PDF
No ratings yet
CS 3591 Networks Lab Manual - Updated Oct - 18 (2024)
79 pages
C JAVA Sockets Examples
PDF
No ratings yet
C JAVA Sockets Examples
10 pages
Network Lab by Armstrong
PDF
No ratings yet
Network Lab by Armstrong
52 pages
CN Record EX3 TO 10
PDF
No ratings yet
CN Record EX3 TO 10
39 pages
Unps Lab Manual PDF
PDF
No ratings yet
Unps Lab Manual PDF
23 pages
COE 4DN4 Lab1: DNS-Domain Name Server
PDF
No ratings yet
COE 4DN4 Lab1: DNS-Domain Name Server
10 pages
Network Lab Manual
PDF
No ratings yet
Network Lab Manual
32 pages
Work Program
PDF
No ratings yet
Work Program
13 pages
Computer Network Programs Vtu
PDF
No ratings yet
Computer Network Programs Vtu
24 pages
Computer Network Lab
PDF
No ratings yet
Computer Network Lab
27 pages
Cs8581 Networks Laboratory List of Experiments
PDF
No ratings yet
Cs8581 Networks Laboratory List of Experiments
15 pages
Network Lab - 6
PDF
No ratings yet
Network Lab - 6
13 pages
Ex - No.1 S S W P: B Imulation OF Liding Indow Rotocol
PDF
No ratings yet
Ex - No.1 S S W P: B Imulation OF Liding Indow Rotocol
11 pages
CN LAB Ex3
PDF
No ratings yet
CN LAB Ex3
9 pages
CN Record Print
PDF
No ratings yet
CN Record Print
36 pages
Computer Network 2
PDF
No ratings yet
Computer Network 2
13 pages
Networking Lab
PDF
No ratings yet
Networking Lab
54 pages
Network/Socket Programming in Java: Rajkumar Buyya
PDF
No ratings yet
Network/Socket Programming in Java: Rajkumar Buyya
39 pages
Networking Lab Assignment: Name: Univ. Roll: Year: 3 Stream: It
PDF
No ratings yet
Networking Lab Assignment: Name: Univ. Roll: Year: 3 Stream: It
14 pages
CS2307 - Network Lab Manual
PDF
67% (6)
CS2307 - Network Lab Manual
66 pages
3591 CNlab Program
PDF
No ratings yet
3591 CNlab Program
67 pages
Network Programming
PDF
No ratings yet
Network Programming
40 pages
TCP/IP Application Interface
PDF
No ratings yet
TCP/IP Application Interface
22 pages
CN Lab Manual
PDF
No ratings yet
CN Lab Manual
62 pages
CN Lab File
PDF
100% (2)
CN Lab File
35 pages
File Transfer TCP Algorithm: Program 6
PDF
No ratings yet
File Transfer TCP Algorithm: Program 6
13 pages
Args Number Temp SC S sc1 S Number SC P S P Number Temp sc1 Temp
PDF
No ratings yet
Args Number Temp SC S sc1 S Number SC P S P Number Temp sc1 Temp
9 pages
CN Lab Program
PDF
No ratings yet
CN Lab Program
28 pages
Cse CN
PDF
No ratings yet
Cse CN
60 pages
L1F21BSCS0463 Lab6
PDF
No ratings yet
L1F21BSCS0463 Lab6
9 pages
CCS Record Printout
PDF
No ratings yet
CCS Record Printout
62 pages
2021UCP1387 CN Assign-1
PDF
No ratings yet
2021UCP1387 CN Assign-1
10 pages
CS22B2043 Lab6
PDF
No ratings yet
CS22B2043 Lab6
13 pages
Networking Lab
PDF
100% (1)
Networking Lab
68 pages