Sunday 15 August 2010

c - how to calculate numbers in tcp server -


I have an assignment on the C language with socket programming I dont know how to do that how to start Writing is a TCP server (not FORK ()) with the SELECT () functions, the server needs to filter the number of N numbers given by clients connected to this server. The server needs to print the largest number of N and the client's IP address that connects the server to the server with the telnet service in the terminal

I already have a TCP server but I do not know Thanks for your help in getting the numbers sent by customers

using a Telnet server To make you have a socket one port Number must be tied. The standard telnet port is 23 As you are already part of the server, clients connect to the server; I send you the portion that reads the number, copy it and paste it into your program. To use it, simply call the ProcessNation () function with an acceptable socket.

  // Define some #define return 13 #NEWLINE 10 # escape 27 # define backspace 8 / this is the maximum number accepted per session / UK You can change it to be dynamic, hint and maulock, which you want # MAX_NUMS 250 integers [MAX_NUMS]; // echo to the characters typed remotely; int doEcho = 0; // Return the amount of IT int sumThemUp (int count) {int sum = 0, i = 0; For (i = 0; i  number [i]) ret = the digits [i]; Return writ; } Zero Process Connection (Socket WConSock) {fd_set sfds; Structure Timeual Timeout = {0, 0}; Four Act New [12]; Int number number = 0; Four f; Four * Welcomecome1 = "Welcome to my TeleNet Emulator \ r \ n; Four * Welcome Message2 =" Please type a number and press enter \ r \ n "; Char * WelcomeMessage3 =" Esc to end the session Press the key \ r \ n "; char * WakeUpMessage =" Are you sleeping?, Normal wake up! !! Send Sent (wConSock, WelcomeMessage1, strlen (WelcomeMessage1), 0); Send (wConSock, WelcomeMessage2, strlen (WelcomeMessage2), 0); Send (wConSock, WelcomeMessage3, strlen (WelcomeMessage3) ), 0); Memset (Actonum, 0, Saffoff (Actonum); MEMSAT (number, 0, size (integer) * MAX_NUMS; Int KeepOnReading = 1; while (KeepOnReading) {FD_ZERO (& amp; sfds); FD_SET (WConSock, & amp; sfds); timeout.tv_sec = 60; // timeout of 1 minute. TV_Usek = 0; switch (select (1, & sfds, NULL, NULL, and timeout)) {Default: // socket There are errors, turn it off and turn off (wConSock); return; Case 0: // time If sent (sent!), Send (wConSock, WakeUpMessage, strlen (WakeUpMessage), 0); sentSleep = 1; breakage; case 1: // data in socket, let's read it (recol (wConSock, & amp; Case '2': Case '3': Case '4'; ' Case: '5': Case '6': Case '7': Case '8': Case '9': If (Strangel (Actonam) & lt; 10) Stranket (Actonum, and CH, 1); If Send (Doo) (wkans sock, and cf, psychof (ca), 0); SentSleep = 0; break; Case Backspace: If (Strannon (Actonum) Actonum [Stellen (Actonum -1) = '\ 0'; Send to doEcho (wConSock, "\ b", 1, 0); break; Case Escape: // Esc KeepOnReading = 0; break; Case return: If you send (doChoose) (wConSock, "\ r \ n", 2, 0); If (Stellan (Actonum)) [nnge [number] = ato (act no); If (the number [numbers]> gt; 0 and number number & lt; MAX_NUMS) number + + +; Memset (Actonum, 0, Saffoff (Actonum)); } break; } } break; }} Four lessons [64]; Sprintf (text, "\ n \ n \ r has been entered:% 10d \ r \ n", numbers); Send (wConSock, text, strlen (text), 0); Sprintf (text, "Sum of numbers:% 10d \ r \ n", sumThemUp (numNums)); Send (wConSock, text, strlen (text), 0); Sprintf (text, "smallest number:% 10d \ r \ n", meet greatest (numNums)); Send (wConSock, text, strlen (text), 0); Sprintf (text, "largest number:% 10d \ r \ n", getBiggest (numNums)); Send (wConSock, text, strlen (text), 0); Strcpy (text, "\ r \ n \ nPress any key to leave ..."); Send (wConSock, text, strlen (text), 0); Recv (wConSock, & amp;;;; sizeof (ch), 0); Close (wConSock); }    

No comments:

Post a Comment