Thông tin liên lạc bằng cách sử dụng TCPBây giờ, chúng tôi thảo luận về thông tin liên lạc kết nối theo định hướng, đồng thời sử dụng dịch vụ của TCP (trường hợp của SCTP sẽ là tương tự). Con số 17,11 cho thấy sơ đồ dòng chảy chung của loại giao tiếp.Máy chủ quá trìnhThe server process starts first. It calls the socket function to create a socket, which we call the listen socket. This socket is only used during connection establishment. The server process then calls the bind function to bind this connection to the socket address of the server computer. The server program then calls the accept function. This function is a blocking function; when it is called, it is blocked until the TCP receives a connection request (SYN segment) from a client. The accept function then is unblocked and creates a new socket called the connect socket that includes the socket address of the client that sent the SYN segment. After the accept function is unblocked, the server knows that a client needs its service. To provide concurrency, the server process (parent process) calls the fork function. This function creates a new process (child process), which is exactly the same as the parent process. After calling the fork function, the two processes are running concurrently, but each can do different things. Each process now has two sockets: listen and connect sockets. The parent process entrusts the duty of serving the client to the hand of the child process and calls the accept function again to wait for another client to request connection. The child process is now ready to serve the client. It first closes the listen socket and calls the recv function to receive data from the client. The recv function, like the recvfrom function, is a blocking function; it is blocked until a segment arrives. The child process uses a loop and calls the recv function repeatedly until it receives all segments sent by the client. The child process then gives the whole data to a function (we call it handleRequest), to handle the request and return the result. The result is then sent to the client in one single call to the send function. We need to emphasize several points here. First, the flow diagram we are using
đang được dịch, vui lòng đợi..
