Reputation: 487
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?
Upvotes: 0
Views: 998
Reputation: 63190
To receive anything over a socket you'll need to call recv
and check that for as long as the return value is larger than 0, you write the incoming data to wherever you wish.
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.
Upvotes: 2