I am working on homework issues for class. I want to start a UDP server which listens for a file request opens the file and sends it back to the client requesting with the UDP.
Here is the server code.
// Create UDP socket if ((sockfd = socket (AF_INET), SOCK_DGRAM, 0)) == -1) {glitch ("can not create socket"); Exit (-1); } // Configure socket memstant (& server, 0, size server); Server.can_family = AF_INET; // Use the IPv4 server. Sine_addr.s_addr = htonl (INADDR_ANY); // My IP server. Sin_port = htons (atoi (argv [1])); // server port // bind socket if ((bind (scaffold, (structure sokadar *) and server, size (server))) == -1) {closed (sockfd); Lies ("can not bind"); } Printf ("Listener: Waiting with recvfrom ... \ n"); If (listen (sockfd, 5) == -1) {lie ("can not listen for connection"); Exit (-1); } While (1) {client_len = sizeof (struct sockaddr_in); Newsockfood = Acceptable (Sokfad, (Structured Socder *) and Client, and Client_LAN); If (Newsflof <0) {false ("error on acceptance"); } // How do some parse requests // I use recv or recvfrom? // Do I send new UDP socket to send back data to client? Send File (NewsForF, Filename); Close (newsockfd); } Closed (sockfd);
How do I lose data How do I read data from clients? And how can I return a new UDP connection to the customer?
No comments:
Post a Comment