unix2016 assignment10 note
Requirements
Write a program to determine your system’s byte ordering. Explain how does it work and present your test results.
Write a client program and a server program to continuously report the number of processes currently running on a specified host (UNIX) computer. Make sure your server supports multiple concurrent clients and handle socket-related exceptions.
Implements
- byte ordering
- 用casting,將int(32bit) cast 成 char(8bit)
- 檢查char 是哪兩個byte,就能知道系統的byte ordering
- socket
- sysinfo contains procs,
1 | struct sysinfo si; |
- server
- getaddrinfo(), traversal the result list to get a available socket
- socket() create a socket descriptor
- bind() bind portnumber with the socket descriptor
- listen() listen on the port
- accept() wait for a connection
- after accept a connection, create a new process to handle clients
- write sth to the socket descriptor
- client
- getaddrinfo(), traversal the result list to get a available socket
- socket() create a socket descriptors
- connect() connect to remote host
- read() read from the socket descriptor