且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

客户端到客户端消息传递在套接字编程中

更新时间:2022-10-15 14:14:13

One way to accomplish this is have one of the client to act as a server after some communication over actual server. You need to create a protocol of yours. That being said:

1- Client A: -Hey, Server!. Tell the Client B to create a comm server so I can communicate directly with him.

2- Server: -Hey, Client B!. Start a server instance and tell me the connection properties so i can relay it Client A, so he can connect to you.

3- Client B: -Hey, Server!. I'm ready to accept the connection request for Client A. Here's my connection properties...

4- Server: -Client A!! Here the connection properties of Client B. Take it or leave it... I'm done..

5- Client A: -Hey, Server B!.. Can i connect?..

That is the protocol.. So any client first initiates a request to server that includes the message type of "me, requesting to connect to client x..". Server commands the client x, client x responses, server relays the response to initiator client... And also you should implement the error handlings, denial policies or some other things you can think of in order to manage the whole protocol.

相关阅读

技术问答最新文章