Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于服务端和多客户端的问题 #399

Open
thinbug opened this issue Oct 7, 2023 · 6 comments
Open

关于服务端和多客户端的问题 #399

thinbug opened this issue Oct 7, 2023 · 6 comments

Comments

@thinbug
Copy link

thinbug commented Oct 7, 2023

我想实现一个类似聊天的程序,服务端是否这样来实现,有点模糊。

1,是否需要对应每个客户端都需要创建一个kcp(因为conv需要匹配)
2,如果socket收到数据,我如何对应相应的客户端,用IP和端口吗

例如:服务端一个udp socket,bind一个端口
客户端发送消息,在服务端会对每个第一次来消息的客户端连接都创建一个kcp(因为conv需要匹配),我在socket收到消息根据remote ip和port来判断对应的conv(是否合适),用这个conv的kcp来input,不知道这样使用有没有问题?

@skywind3000
Copy link
Owner

skywind3000 commented Oct 7, 2023

聊天机器人无实时性要求,请用 TCP

@thinbug
Copy link
Author

thinbug commented Oct 8, 2023

单纯的学习实践一下,后面可能做游戏方面的。

@skywind3000
Copy link
Owner

  1. 是的,一条连接一个 kcp 对象。
  2. 用 socket 编号去对应啊。

@thinbug
Copy link
Author

thinbug commented Oct 8, 2023

感谢skywin3000的回复,我有点小白,第2点没看懂
int recvfrom(int sockfd,void *buf,int len,unsigned int lags,struct sockaddr *from,int *fromlen);
我用socket接收数据,只有一个from,你说的编号是什么?我服务端只有一个udpscoket。

@skywind3000
Copy link
Owner

那靠包头的 conv 区别用户,这个 conv 由你服务端分配,客户端带上来匹配,然后检测来源端口和地址是否匹配。

@thinbug
Copy link
Author

thinbug commented Oct 9, 2023

明白,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants