Commit 23f4eaa6 authored by Zhaozhong Liu's avatar Zhaozhong Liu
Browse files

prellllab 4 completed

parent 25e5dd1a
1. Like open(2), socket(2) returns a file descriptor for the new socket that has been established so that it can be determined where write and read, or in the case of socket, send and receive should occur: these are syscalls very similar in nature to write and read. It is different because open requires an argument that specifies read and/or write, whereas a socket is a bidirectional communication system by default. Here it is also different from pipes since pipes are unidirectional communication systems by default. Also, socket have different arguments required. Socket creates a comm endpoint.
2.
1) the program can address another thourgh a TCP socket and it will be done via a port number for an IP. The other program is receving the data sent by the first. And it also uses that port to revcieve the information.
2)The main purpose of that is to assgin the address to a socket. Bind takes ina pointer to the address and the file desciptor for the socket.
3)The connect() function conncet the socket in its first arguement and to the address in its second argument. This kind of conncetion have to be before any communication occur.
4)The listen() function is the system call that can marks a socket to inform that it will be used to accept incomming connection request.listen has to be implemented before any accept() calls in order to acceept the incoming requests and create new sockets.
5)The accept()takes a socket marked to the listening state. And it extracts the first conneccction request on the queue of pending conncetions. Creates a new conncected socket, and returns a fiiile descriptor referring to that new connceted socket.
6) Firstly, we will have the address data structure being prepared, and also zero out the sockaddr sturcture. We also set up the local IP whihch will be used by a socket() system call later. Then use conncet() to the adress from sockaddr and wait for an incoming conncetion. We make the listen call until there is another sockect that want to connect. At that moment, the accept(0 will promote the incomming conncetion through the new socket. After that I can use send system call and receive system call to write and read through the socket.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment