i made client/server program in that the client send strings to server ,then the server send it back to the server the length of the string that entered by the client ,so i added feature as this
when the client press "--" the server close the socketfd for that client then the client terminate its program as this
Client_side> please enter a sequence of characters followed by the new-line character:
hello students (input from a user)
Client_side > sending "hello students" to the server
Client_side > length= 14
Client_side > please enter a sequence of characters followed by the new-line character:
And the same happens again until the user quits by typing --.
Server_side > waiting for client messages.
Sever_side > reveiced "hello students" from the client (IP address, port #)
Server_side > Sending "14” to the client
Server_side > waiting for client messages
Server_side > received quit from client ...Goodbye (assuming the client typed --)
but i want to add to server code confirm question that when the user type "--" show the question : "Are you sure to exit Y/N ?"
if he type "y" then the server close the connfd for that client then the client will exit
Why are you trying to add this to the server code?
Servers run unattended in the background.
If there was a place to ask this, it would be in the client code, just before sending the message off to the server.
Oh, and when you do this
n = recv( sock, buff, sizeof(buff), 0 );
you should do this
n = recv( sock, buff, sizeof(buff)-1, 0 );
so that you always have room to append the \0.
Also, make sure you close the socket on the client end, rather than just returning from the function.
Thnx very muvch for your replay...
i will try your advice and tell you what will happen...