Long description

Back

The 49 lines of code are as follows.

0. forward slash asterisk Preliminaries colon

1. svr Sock colon the main server socket coma bound to T C P port 12345

2. to Send colon database to track what data we still have to send to the client

3. dash to Send.put open parenthesis fd coma msg close parenthesis will register that we need to send msg on fd

4. dash to Send.get open parenthesis fd close parenthesis returns the string we need to send msg on fd

5. dash to Send.destroy open parenthesis fd close parenthesis removes all information about fd from to Send asterisk forward slash

6.

7. inFds equals to open curly bracket close curly bracket forward slash asterisk file descriptors to watch for incoming data asterisk forward slash

8. outFds equals to open close curly bracket forward slash asterisk file descriptors to watch to see if sending is possible asterisk forward slash

9. exceptFds equals to open close curly bracket forward slash asterisk file descriptors to watch for exception conditions open parenthesis not used close parenthesis asterisk forward slash

10.

11. char msgBuf open box bracket MAX under score MSG under score SIZEclose box bracket forward slash asterisk buffer in which to receive messages asterisk forward slash

12. char asterisk thank You Msg equals to double quote Thank you exclamation mark double quote forward slash asterisk reply to send back asterisk forward slash

13.

14. while open parenthesis TRUE close parenthesis

15. open curly bracket

16. forward slash asterisk block until some file descriptors are ready to be used asterisk forward slash

17. rdyIns coma rdyOuts coma rdyExcepts equals to select open parenthesis inFds coma outFds coma exceptFds coma NO under score TIMEOUT close parenthesis

18.

19. for open parenthesis fd in rdylns close parenthesis forward slash asterisk iterate over all the connections that have something for us asterisk forward slash

20. open curly bracket

21. if open parenthesis fd equals to equals to close parenthesis forward slash asterisk a new connection from a client asterisk forward slash

22. open curly bracket

23. newSock equals to accept open parenthesis close parenthesis forward slash asterisk create new socket for client asterisk forward slash

24. inFds equals to inFds U open curly bracket newSock close curly bracket forward slash asterisk must monitor it also asterisk forward slash

25. close curly bracket

26. else

27. open curly bracket forward slash asterisk receive the message from the client asterisk forward slash

28. n equals to receive open parenthesis fd coma msgBuf coma MAX under score MSG under score SIZE close parenthesis

29. printf open parenthesis double quote Received colon percent s.0 coma msgBuf close parenthesis

30.

31. open parenthesis fd coma thank close parenthesis forward slash asterisk must still send thank on fd asterisk forward slash

32. outFds equals to outFds U open curly bracket fd close curly bracket forward slash asterisk so must monitor this fd asterisk forward slash

33. close curly bracket

34. close curly bracket

35. for open parenthesis fd in rdyOuts close parenthesis forward slash asterisk iterate over all the connections that we can now thank asterisk forward slash

36. open curly bracket

37. msg equals to open parenthesis fd close parenthesis forward slash asterisk see what we need to send on this connection asterisk forward slash

38. n equals to send open parenthesis fd coma msg coma strlen open parenthesis msg close parenthesis close parenthesis

39. if open parenthesis n less than strlen open parenthesis thank close parenthesis

40. open curly bracket

41. open parenthesis fd coma msg plus n close parenthesis forward slash asterisk remaining characters to send next time asterisk forward slash

42. close curly bracket else

43. open curly bracket

44. open parenthesis fd close parenthesis

45. outFds equals to outFds backward slash open curly bracket fd close curly bracket forward slash asterisk we have thanked this one already asterisk forward slash

46. close curly bracket

47. close curly bracket

47. close curly bracket

Back