新套接字的名称

Name for new socket

我正在学习套接字编程,但遇到了问题。我希望当人们连接到我的服务器时,我会看到他的名字(例如 "on server connected Richard" )。如何为套接字分配名称。 P.S。对不起我的英语。

你不知道。我的意思是你没有 "assign a name to a socket"。相反,您应该保留某种结构,其中包含套接字以及该连接所需的所有关联数据,例如连接的用户名。

例如类似于

struct user
{
    SOCKET      socket;  // The users connected socket
    std::string name;    // The name of the connected user
    // TODO: Other attributes needed for the user or the users connection
};

具体如何获取用户名是另一个问题(尽管我可以给你一个提示:状态)。