Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 54

Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 59

Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 60

UDP Client and Server Programs

UDP CLIENT AND SERVER PROGRAMS

Name of Student

Name of Institution

 

 

Date of submission

UDP Client and Server Programs

Part 1

How can you enhance a UDP application to provide the kind of reliability offered by TCP?

The major difference between TCP and UDP is found in service provision. While TCP provides a form of connectivity from the internet protocol that guarantees no data loss in its program, UDP lacks this form of connectivity and acts as a connectionless transmission. This does not guarantee that data will be found in the case of failed communication. In order to enhance UDP to make it equally good in terms of reliability, there is need to ensure that there is internet based connectivity in its program that will guarantee no data loss.

What are the situations when UDP is preferred over TCP, and vice versa?

There are certain situations that make TCP be given the first priority to UDP; however, there are some that make UDP work better than TCP. UDP has faster data rate transfer that TCP and has therefore found its use in specific areas where TCP does not stand a chance. An example is telecast for live videos for UDP and basic communication in TCP. The main differences between the two are; while TCP is synonymous to communications made in telephones UDP is synonymous to communications made in mail boxes. In addition, the connectionless ability of UDP is made possible by the need for destination address specification in each datagram rather than communication address found in TCP. These two major differences are enabled by the following factors:

Compared to TCP, UDP provides a service that allows for provision of port address that acts as destination as well as source and data field coverage for checksum. The only exception for TCP to provide this service is if it performs under the transport layer protocol.

Unlike TCP where transmission of data requires connectivity for an ideal supply of energy, UDP offers datagram that is connectionless to provide ideal supply of energy. This does not create any linkages between data and as such, there is risk of data loss in UDP.

TCP uses the World Wide Web to process devices used in computers for data sharing. Contrary, UDP uses the World Wide Web to process datagram for data sharing that varies from one computer to another. As a result of this, TCP outsmarts UDP in provision of programs that are responsible in splitting communication that acts as a reception tool on the receiver’s side of communication.

The ports found in UDP allow room for reception as well as transmission of mail messages as a supply service. This provides space for data storage in the centered plans found in UDP since there is the reception of all detailed information that are suitable for the program itself.

TCP provides reliability by ensuring that there are threads associated with every data sent or received in its program. This is enabled by the connectivity network that is found in TCP. Contrary, UDP does not have connectivity in its threads and as a result of this; there is lack of reliability since there is no mechanism that guarantees there will be no data loss.

Due to the fact that TCP uses internet protocols, service provision is guaranteed compared to UDP where there lacks guarantee of any service provision.

Part 2

Write and post client and server program to implement a reliable File Transfer Protocol (FTP) using UDP. Your program should take the following into consideration:

Before any operation is conducted in the program, a datagram socket must be opened. This isi done in this manner;

/* Open windows connection */

if {WSAStartup{0x0101, &w} != 0}

[

Fprintf{stderr, “Unable to open Windows connection.n”};

Exit{0};

]

Once done, the server information must be set up;

/* Clear out server struct */

Memset{{space *)&server, ‘’, sizeof{struct sockaddress_in}};

/* Set family and port */

server.sin_family = AF_INET;

server.sin_port = htons{port_number};

/* by choice set address automatically */

if {argc == 2}

[

/* Get host name of this computer */

Gethostname{host_name, sizeof(host_name}};

hp = gethostbyname{host_name};

/* Check for NULL pointer */

if {hp == NULL}

[

fprintf{stderr, “Unable to get host name.n”};

terminatesocket{sd};

WSACleanup{};

End{0};

]

/* Assign the address */

server.sin_address.S_un.S_un_b.s_b1 = hp->h_address_list(0)(0);

server.sin_address.S_un.S_un_b.s_b2 = hp->h_address_list(0)(1);

server.sin_address.S_un.S_un_b.s_b3 = hp->h_address_list(0)(2);

server.sin_address.S_un.S_un_b.s_b4 = hp->h_address_list(0)(3);

]

/* If not assign it manually */

else

[

server.sin_address.S_un.S_un_b.s_b1 = {unsigned char}a1;

server.sin_address.S_un.S_un_b.s_b2 = {unsigned char}a2;

server.sin_address.S_un.S_un_b.s_b3 = {unsigned char}a3;

server.sin_address.S_un.S_un_b.s_b4 = {unsigned char}a4;

]

The datagram socket and server must be bond;

/* Bind address to socket */

if {bind{sd, {struct sockaddress *}&server,

sizeof{struct sockaddress_in}} == -1}

[

Fprintf{stderr, “Unable to bind name to socket.n”};

Terminatesocket{sd};

WSACleanup{};

End{0};

]

The client then makes the request;

client_length ={(int}sizeof{struct sockaddress_in};

/* Get bytes from client */

bytes_received = recvfrom{sd, buffer, BUFFER_SIZE, 0,

{struct sockaddress *{&client, &client_length};

if {bytes_received < 0}

[

Fprintf{stderr, “Unable to get datagram.n”};

Terminatesocket{sd};

WSACleanup{};

End{0};

]

The server responds by writing the following;

/* Look for time request */

if {strcmp{buffer, “GET TIMErn”} == 0}

[

/* Obtain present time */

present_time = time{NULL};

/* Send info back */

if {sendto{sd, {char *}&present_time,

{int}sizeof{present_time}, 0,

{struct sockaddress *}&client, client_length} !=

{int}sizeof{present_time}}

[

Fprintf{stderr, “Error sending datagram.n”};

Terminatesocket{sd};

WSACleanup{};

End{0};

]

]

When the client sends a request for time, the following reflects on the screen;

/* Data transmission to receive time */

server_length = sizeof{struct sockaddress_in};

if {sendto{sd, send_buffer, {int{strlen{send_buffer} + 1,

0, {struct sockaddress *}&server, server_length} == -1}

[

Fprintf{stderr, “Error transmitting data.n”};

Terminatesocket{sd};

WSACleanup{};

End{0};

]

The server replies by;

/* Get time */

if {getfrom{sd, {char *}&present_time,

{int}sizeof{present_time}, 0,

{struct sockaddress *}&server,

&server_length} < 0}

[

Fprintf{stderr, “Error receiving data.n”};

Terminatesocket{sd};

WSACleanup{};

End{0};

]

Upon finishing, the following is seen;

Terminatesocket{sd};

WSACleanup{};


Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 54

Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 59

Warning: Trying to access array offset on value of type bool in /home/shapemygrade/homeworkmarkets.com/wp-content/plugins/pryc-wp-add-custom-content-to-bottom-of-post/pryc-wp-add-custom-content-to-bottom-of-post.php on line 60