这是场景:
我在 Linux 中使用 telnet 实用程序连接到服务器。建立连接后,客户端应输入参数,服务器应读取该参数。
这是服务器代码:
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;
}
当我使用 telnet 进入服务器时:telnet servername portnumber
客户端接收:Enter Command:
我想在其前面输入参数。例如Enter Command: Hey There!
我要做的就是Hey There!
将其读取存储在string
服务器上并打印出来。我怎样才能做到这一点?