简体   繁体   中英

JAVA Socket communication Client -> Server -> Client

So I have this little java project about chatting..

I am able to create a Threaded server and able to connect and communicated with the server using input and output streams.

Now my problem is that if a second client enters the Server I want the first client to be able to communicate with the second client vice-versa.. Also if a third client is connected to the server I don't want the third client to be able to communicated the the first and second clients.

How can I do it??

Use some array of list to hold your clients and then for a user you can do

if (list.indexOf (user) == 0 || list.indexOf (user) == 1) {
    if (list.indexOf (sendto) == 0 || list.indexOf (sendto) == 1) {
        // chat OK
    }
}

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