c unix- Select() send and receive with same socket descriptor
- by RileyVanZeeland
I am wanting to use select to receive and send on a client/server on the same socket descriptor (serverside).
timestruct* myTime;
sockfd = accept(listeningFd, 0, 0);
while(1)
FD_ZERO(&my_fd_set)
maxFd = sockfd
FD_ZERO(&my_fd_set);
FD_SET(sockfd, &my_fd_set);
select(maxFd+1, &my_fd_set, &my_fd_set, NULL, myTime);
for (j=0; j<=maxFd; j++)
if(FD_ISSET(j, &temp_fd_set))
if(j==sockfd)
send()
if(j==sockfd)
recv()
This is essentially what I want to do. Obviously this won't work because sockfd is going to be the same value for sending and receiving. Is there a way I can do this without using fork()??
Currently I have a blocking recv and send but the server could be required to recv multiple commands while another command is being processed to send back to the client.
I am very knew to c and also 'select()'. Because select has the three fd_set options (read, write, execute) I thought maybe I could do this.
Thank you.