简体   繁体   中英

Making a client-server chat - running into issues with connecting client to client

I am trying to learn how to make a multiple-client chatting program. Im following the Oracle tutorial on Custom Networking, but its not really what I am looking for. So far, I have no code of my own to share, all of it is copied from the Oracle tutorial and I think pasting it here would be a copyright infringement(??).

link at: http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html+

client code link: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java

anyway, I have the server-client working where the server tells knock knock jokes, the client reads and prints, then the user replies and so on. how would i start to edit it to have the client talk to the other clients directly?

im sorry, i have no background with networking at all. if anyone can direct me to a informative source better suited to my goals i would appreciate it.

as in the Knock-Knock example, each client connects to the server, but they not mutually directly connected.

There is a solution to make a forwarding sever :Arrange each client an id, and clients use id to identify their talking partners.

To do this, you have to modify the client to server data format from a plain string to a tuple like (String,Id). And, when the server receive the data, it parses out the id, get the corresponding client socket and then write the data.

由于您需要某种“进程间通信”基础结构来允许客户端到客户端通信(可能通过服务器编排的套接字?),因此所需的复杂性水平上升了一个台阶。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM