multiuser chat application on adhoc network in java

为君一笑 提交于 2019-12-12 00:35:10

问题


I'm working on a multiuser chatting application on adhoc network, and one of its features is to allow the user to chat with more than one friend at the same time. Can anybody tell me when to start? Can i use socket programming for this... Is there any other way to do it?


回答1:


You would need to implement a publisher subscriber model.Basically have each of your users implement an interface

interface chatWithUser {
   public String getMessage();

   public List<ChatWithUser> getFriends();
}

All these users are subscribers to the chat feature. Now we will have a publisher which would have a list of subscribers. Now when a request for chat comes from a users socket the publisher will check the list of users

public class PublishChattMessage
{
   List<chatWithUser> userChatList;

   public void setUpChat(ChatUser mainUser )
  {
     for(ChatWithUser user:userChatList)
     {
         List<ChatUser> userList = user.getFriends()
        // set up connections with all friends
     }
  } 

  /**
   *  Method to chat between two users. u
   **/
  public void chat(ChatUser userOne,ChatUser user2)
  {

  }
}

Once the connection is set up with all friends then call the chat method and display the messages



来源:https://stackoverflow.com/questions/19080636/multiuser-chat-application-on-adhoc-network-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!