CS 2073 Handout 5 Fall 2014 Program 8

Feb 3rd, 2012
Studypool Tutor
The University of Texas at San Antonio
Price: $20 USD

Tutor description

A client and server program to send short text messages over a network The code you are provided is for two different programs. The file udpclient.c solicits a line of text from the user and sends it to the IP address that the user provides. The text is sent in a UDP datagram, which is an unreliable delivery service. The sender of a UDP datagram has no way of knowing if it was received. The file udpserver.c implements a very simple service protocol: listen for udp datagrams and when one is received, write the contents to the screen. We will discuss these programs in class. You assignment is to modify the udpserver to send the datagram it receives back to the client. The udpclient should be modified to receive this datagram that is sent back and write it to the screen. Note that because udp datagrams may be lost, the client should not wait forever for one to arrive. This will require what is known in LINUX as non-blocking I/O.

Word Count: 1030
Showing Page: 1/5
########################UPD SERVER Program#########################include #include #include #ifdef WIN#include #include #endif#ifndef WIN#include #include #include #include #include #endif#define PORT 20009/* simple upd server this program receives short messages (<99 characters) from any IP address and writes them to the display be sure to use the linker line option "-l wsock32"*/int main(){ /* first define a socket a socket is an I/O port like a file descriptor */#ifdef WIN SOCKET sock; /* SOCKET is a typedef for a structure */#else int sock;#endif int size; int nbytes, flags;#ifdef WIN int addrlen;#else socklen_t addrlen;#endif int i; /* char loopback[20]="127.0.0.1"; */#ifdef WIN WSADATA wsaData; /* This is struct holds Windows required data */ int nCode;#endif char buffer[100]; struct sockaddr_in server; /* this holds my IP address and port info */ struct sockaddr_in from; /* this holds the same info for the sender of the packet I received */ /* the call to WSAStartup is Windows magic */#ifdef WIN if((nCode = WSAStartup(MAKEWORD(1,1), &wsaData)) != 0) { printf("Opps! WSA error %d\n",nCode); exit; }#endif /* create a socket called sock. It is a datagram socket */

Review from student

Studypool Student
" Awesome! Exactly what I wanted. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1820 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors