Skip to content

message_protocol

achivaq01 edited this page Nov 27, 2023 · 1 revision

CrazyServer Message Explanation

This document provides an explanation of the messages sent and received in the CrazyServer WebSocket implementation.

Message Types

1. Private Message

  • Type: private
  • From: server
  • Value: Welcome message sent to clients upon connection.

2. Connected Message

  • Type: connected
  • From: server
  • Id: Unique identifier for the connected client.
  • Description: Notifies the server about a new client connection.

3. Disconnected Message

  • Type: disconnected
  • From: server
  • Id: Unique identifier for the disconnected client.
  • Description: Notifies the server about a client disconnection.

4. New Message Notification

  • Type: new message
  • Id: Unique identifier for the client sending the new message.
  • Description: Notifies other connected clients about a new message.

5. New Connection Notification

  • Type: new connection
  • Id: Unique identifier for the newly connected client.
  • Description: Notifies other connected clients about a new client connection.

6. New Disconnection Notification

  • Type: new disconnection
  • Id: Unique identifier for the disconnected client.
  • Description: Notifies other connected clients about a client disconnection.

7. Login Message

  • Type: login
  • Success: Boolean indicating the success of the login attempt.
  • Description: Sent by clients to authenticate with the server.

8. List Message

  • Type: list
  • List: Array containing client information (id and platform).
  • Description: Sent by the server to provide a list of connected clients.

9. Print String Message

  • Type: string
  • Text: The text message to be displayed on the server screen.
  • Description: Instructs the server to display a moving message on the screen.

10. Print Image Message

  • Type: image
  • Img: Base64-encoded image data.
  • Description: Instructs the server to display an image on the screen.

Message Flow

  1. Client Connection:

    • Client sends a connected message.
    • Server responds with a private welcome message and notifies other clients about the new connection.
  2. Client Disconnection:

    • Client sends a disconnected message.
    • Server broadcasts the disconnection to other clients.
  3. Client Sends Message:

    • Client sends a message with type string or image.
    • Server processes the message and notifies other clients if needed.
  4. Client Login:

    • Client sends a login message with user credentials.
    • Server validates the credentials and responds with a success or failure message.
  5. Client Requests Client List:

    • Client sends a list message.
    • Server responds with a list of connected clients.

Additional Notes

  • Messages are exchanged using JSON format.