Here’s the scenario:
I connect to a server using telnet utility in Linux. After the connection is established client should enter and argument which should be read by a server.
Here’s the server code:
int main(void)
{
int new_fd;
char *string;
// Establish the connection
if (send(new_fd, "Enter Command: ", 15, 0) == -1)
perror("send");
// Here I want to accept the argument from the server
return 0;
}
When I telnet into server using: telnet servername portnumber
client receives : Enter Command: in front of which I want to type in the argument.
for e.g. Enter Command: Hey There!
All I want to do is read Hey There! store it in string at the server and print it. How can I do that?
To receive anything over a socket you’ll need to call
recvand check that for as long as the return value is larger than 0, you write the incoming data to wherever you wish.From here