PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How Websockets distinguish the Data Being Sent

 April 13, 2022     phpwebsocket, websocket     No comments   

Issue

I am reading on how to implement websockets. For now I am looking at the fancywebsockets implementation since it is easier to setup. My question is more catered on understanding websockets in general so I like to have some classification on this.

  1. Can you control the data that is being sent by the WS (I.E client receiving the data)?

  2. How do you deal with in, let's say a Private message scenario, where you also store the message in the database. If you store a text in the DB and display the message on the screen, how does WS goes about putting that change in other people browsing that page. (Does the WS listen to every changes that occurred in that PAGE?). A clear example would be in facebook, where two people browsing the same wall sees the update of the wall owner?

  3. Although a bit unrelated, but curious question. If websockets provide us a realtime update on data, why hasn't anyone created a fork version of Google Wave services. Is it because not every browser has a definite implementation of it?

Thanks.


Solution

About 1. Really I don't understand this question, Websockets connection is the same as TCP connection, you can modify received date before sending it back. Simple example in Bristleback Server (Server gets a preview of edited user status, then checks whether it contains illegal words and then complete preview of the status is sent back to the user:

@ActionClass
public class ClientNotificationUpdateAction {

  @Action
  public UserStatus previewEditedStatus(FacebookUser user, UserStatus status) {
    removeBadWords(status);
    return status;
  }
}

About 2. WebSockets server has information about all connected users so message can be simple sent to all connected users or additionally filtered to send this notification for example to close friends only. And here's some more code (client updates his status and this status is sent back to all his friends).

@ActionClass
public class ClientNotificationUpdateAction {

  @ObjectSender
  private ConditionObjectSender conditionObjectSender;

  @Action
  public void updateStatus(FacebookUser user, UserStatus status) throws Exception {
    SendCondition sendToFriendsOfUser = new FiendsOfUserCondition(user);

    BristleMessage message = ActionMessageFactory
      .createMessage("ClientNotificationUpdate", "updateStatus", status);
    conditionObjectSender.sendMessage(message, sendToFriendsOfUser);
  }
}

About 3. It's true that not all internet browsers implement WebSockets protocol (especially in mobile devices)



Answered By - voitec
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing