[英]Error : “Transport endpoint is already connected”
I am trying to develop a small chat server with C. 我正在尝试使用C开发小型聊天服务器。
For a simple chat server, 对于简单的聊天服务器,
Can i get to see some sample implementations ? 我可以看到一些示例实现吗? I have to use gcc compiler and c language for this assignment. 我必须为此使用gcc编译器和c语言。
You need one socket/client and no, you cannot reuse sockets. 您需要一个套接字/客户端,没有,您不能重用套接字。 If you have to handle multiple clients you can: 如果必须处理多个客户,则可以:
For C socket communication examples The Unix Network Programming book is probably the best source. 对于C套接字通信示例Unix网络编程书可能是最好的资料。 It has ample of example programs and explanation. 它具有大量示例程序和说明。
- ( Transport endpoint ) === ( socket ) ? (传输端点)===(套接字)?
NO. 没有。 "Endpoint" means IP address with Port number. “端点”是指带有端口号的IP地址。 Socket presents one "Session" and session consists of two endpoints, local endpoint(IP, port) and remote endpoint(IP, port). 套接字表示一个“会话”,会话由两个终结点组成,本地终结点(IP,端口)和远程终结点(IP,端口)。
- Do i have to use one socket per client, or can I reuse a socket for multiple clients ? 我必须每个客户端使用一个套接字,还是可以将一个套接字重用于多个客户端? If so, how ? 如果是这样,怎么办?
One socket per one session. 每个会话一个套接字。 That means a server needs to create a new socket for each remote endpoint( client ). 这意味着服务器需要为每个远程端点(客户端)创建一个新的套接字。 You can reuse socket when it's not in use anymore. 您可以在不再使用套接字时重用它。 Look for SO_REUSEADDR socket option. 查找SO_REUSEADDR套接字选项。
- Is there a standard way of doing this ? 有这样做的标准方法吗?
Not sure what you are asking. 不知道你在问什么。 A standard way for chat service or for server/client model? 聊天服务或服务器/客户端模型的标准方法? For chat service, look for IRC. 对于聊天服务,请查找IRC。 Server/Client programming model is well documented. 服务器/客户端编程模型有详细记录。 You can Google it. 你可以谷歌。
- Any good references available ? 有没有好的参考资料?
http://beej.us/guide/bgnet/ http://beej.us/guide/bgnet/
Now I believe you understand what the error message means. 现在,我相信您了解错误消息的含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.