Skip to content

Websocket api

Overview

The WebSocket API provides chat services by communicating with the Socket server via WebSocket. It supports game client connections, channel message transmissions, and more.

The main features of the WebSocket API are as follows.

  • Client connection / disconnection
  • PING / PONG
  • Sending / receiving chat messages
    • Channel chat
    • 1:1 chat
  • Filtering blocked users
    • Do not send messages to blocked users
    • Do not receive messages from blocked users
  • Channel entry and exit notifications

Basic information

This provides basic information that is commonly needed when using the WebSocket API.

Key terms

  • Channel: Chat Room
  • Channel Message: A chat message sent to all users in the joined channel
  • 1:1 Message: A chat message sent only to a specific user

Packet type

The packet types for sending and receiving with the socket server are as follows.

Packet Name Description
CONNECT Connect to the socket server
RESPONSE_CONNECT Response to the CONNECT request
DISCONNECT Disconnect from the socket server
RESPONSE_DISCONNECT Response to the DISCONNECT request
PING Keep connection alive
If the connection is not successful, the server will disconnect on PING request
PONG Response to the PING request
CHANNEL_CHAT Channel chat
RESPONSE_CHANNEL_CHAT Response to the CHANNEL_CHAT request
DIRECT_CHAT 1:1 chat
RESPONSE_DIRECT_CHAT Response to the DIRECT_CHAT request
NOTIFY_ENTER_CHANNEL Channel entry message
NOTIFY_EXIT_CHANNEL Channel exit message
NOTIFY_DELETE_CHANNEL Channel deletion message
NOTIFY_CHANNEL_NOTICE Channel notice message
NOTIFY_CHANNEL_CHAT Channel chat message
NOTIFY_DIRECT_CHAT 1:1 chat message
NOTIFY_DISCONNECT Disconnection message
When the WebSocket connection is idle, and the Json format is invalid, respond with this packet type

Socket connection process

  1. Request a token issuance through the chat Http API on the game server. ※ The issued token is used for connecting to the chat Socket server.

  2. Connection request from the game client to the Socket server

    • WebSocket communication
    • Use the token issued in step 1
    • If the connection is successful, the Socket server will return the information below
    {
        "packetType":"RESPONSE_CONNECT",
        "status": 200,
        "message": "OK",
        "body":{
            "sessionId":"005056fffea3fd10-000400fd-00000797-f67881178d98d1cd-64ae9a76"
        }
    }
    

Socket communication structure

  • JSON format of packet types starting with 'RESPONSE_'

    {
            "packetType":"Packet Type",
            "status":"Status Code",
            "message":"Status Message",
            "body": JSON Object
    }
    

  • Other packet formats

    {
            "packetType":"Packet Type",
            "body":{
                    //JSON data according to packetType
            }
    }
    

The following cases apply when the server disconnects the WebSocket connection.

  • If there are no requests for 1 minute on the client side
  • When it is not in JSON format
  • When the status value is 401 or 403
    • 401 unauthorized
    • 403 forbidden

Response code

This is the response status code.

Status Code Status Message Description
200 Success. Success
400 Bad Request Bad Request
401 Unauthorized Unauthorized
403 Forbidden Forbidden
408 Request timeout Connection closed by server due to no request from client for 60 seconds
409 Conflict User's request conflicts with server status (e.g. when the chat partner is offline in a 1:1 chat)
500 Internal Server Error Internal Server Error

WebSocket API Features

This explains the API requests and responses for each function of the WebSocket API used in the chat service, along with example code.

Client access

Request parameters

Field Name Description Type Required
packetType Client connection command (CONNECT) string Y
body Request data object Y
Request parameters > body
Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
playerId Account identifier
Hive player ID
long Y e.g. 1234
loginKey Token used for access
Chat Http API issued
string Y "eyJhbGciOiJIUzI1NiJ9.eyJnYW1lSW5kZXgiOjEsInBsYXllcklkIjoxMjM0LCJpYXQiOjE3MzAzNjY4MjksImV4cCI6MTczMDM3MDQyOX0.fpg6kqwqp1QN3KuYcjVBr8j0mzjN2doefJ_D6xFxcFY"
extraData User additional information (UTF-8 standard)
(up to 256 Bytes)
string N e.g. "{\"nickname\":\"Test1234\",\"guildname\":\"together\"}"

Response body

Field Name Description Type Required
packetType Response to the connection request (RESPONSE_CONNECT) string Y
status Status code integer Y
message Status message string Y
body Returned data object Y
Response body > body
Field Name Description Type Required Example
sessionId The value returned upon successful connection string Y e.g. "005056fffea3fd10-000400fd-00000797-f67881178d98d1cd-64ae9a76"

Request sample

{
    "packetType": "CONNECT",
    "body":{
        "gameIndex":1,
        "playerId": 1234,
        "loginKey": JWT generated by API server,
        "extraData": Additional information
    }
}

Response sample

{
    "packetType":"RESPONSE_CONNECT",
    "status": 200,
    "message":"OK",
    "body":{
        "sessionId":"005056fffea3fd10-000400fd-00000797-f67881178d98d1cd-64ae9a76"
    }
}

Client Disconnection

Request parameters

Field Name Description Type Required
packetType Client disconnect command (DISCONNECT) string Y
body Request data object Y
Request parameters > body
Field Name Description Type Required Example
sessionId The sessionId returned upon successful connection string N e.g. "6c2408fffe8c91a8-00002f24-00000032-093b757cdc668383-54b4fbc1"
  • If the sessionId is not specified, the disconnection process for the sessionId assigned to the websocket will be handled.
  • If the sessionId is specified, the disconnection process for that value will be handled.

Response body

Field Name Description Type Required
packetType Response to disconnect request (RESPONSE_DISCONNECT) string Y
status Status code integer Y
message Status message string Y

Request sample

  • If the sessionId is not specified

    {
            "packetType":"DISCONNET"
    }
    
  • When specifying the sessionId

    {
            "packetType":"DISCONNECT",
            "body":{
                    "sessionId":"6c2408fffe8c91a8-00002f24-00000032-093b757cdc668383-54b4fbc1"
            }
    }
    

Response sample

{
    "packetType": "RESPONSE_DISCONNECT",
    "status": 200,
    "message":"OK"
}

PING / PONG

  • Requests are valid only when the socket server and CONNECT are completed
  • Re-login is required if there is no PONG response

Request parameters

Field Name Description Type Required
packetType PING request command (PING) string Y

Response body

Field Name Description Type Required
packetType PONG response command (PONG) string Y

Request sample

{
    "packetType":"PING"   
}

Response Sample

{
    "packetType": "PONG"   
}

Channel message sending

Request parameters

Field Name Description Type Required
packetType Channel message transmission command (CHANNEL_CHAT) string Y
body Request data object Y
Request parameters > body
Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
from Identifier of the account to send the message to the channel
Hive player ID
long Y e.g. 1234
to Channel ID to send the channel message
Created from Chat Http API
string Y e.g. "open:1"
message Message to send to the channel
(up to 200 characters)
string Y e.g. "Hello World!"
langCode Hive language code
(based on ISO 639 alpha-2, languages not distinguished by ISO 639 alpha-2 are separated by Script tag)
string Y e.g. "en"

Response body

Field Name Description Type Required
packetType Response to channel message transmission (RESPONSE_CHANNEL_CHAT) string Y
status Status code integer Y
message Status message string Y

Request sample

{
    "packetType":"CHANNEL_CHAT",
    "body": {
        "gameIndex": 1,
        "from": 1234,
        "to": "open:1",
        "message": "Hello World!",
        "langCode": "en"
    }
}

Response sample

{
    "packetType": "RESPONSE_CHANNEL_CHAT",
    "status": 200,
    "message":"OK"
}

1:1 Message sending

Request parameters

Field Name Description Type Required
packetType 1:1 message transmission command (DIRECT_CHAT) string Y
body Request data object Y
Request parameters > body
Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
from Identifier of the account to send 1:1 messages
Hive player ID
long Y e.g. 1234
to Identifier of the account to receive 1:1 messages
Hive player ID
long Y e.g. 2222
message Message to send 1:1
(up to 200 characters)
string Y e.g. "Hello World!"
langCode Hive language code
(based on ISO 639 alpha-2, languages not distinguished by ISO 639 alpha-2 should be separated by Script tag)
string Y e.g. "en"

Response body

Field Name Description Type Required
packetType Response to 1:1 message transmission (RESPONSE_DIRECT_CHAT) string Y
status Status code integer Y
message Status message string Y
Response body > body
Field Name Description Type Required Example
status Response status code integer Y e.g. 200

Request sample

{
  "packetType": "DIRECT_CHAT",
  "body": {
    "gameIndex": 1,
    "from": 2222,
    "to": 1234,
    "message": "Hello",
    "langCode": "ko"
  }
}

Response sample

{
    "packetType": "RESPONSE_DIRECT_CHAT",
    "status": 200,
    "message":"OK"
}

Socket server event message

This explains the messages sent from the Server to the Client when an event occurs.

This message starts with packetType NOTIFY.

Channel entry message

Field Name Description Type Required
packetType Channel entry message (NOTIFY_ENTER_CHANNEL) string Y
body Request data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
channelId Channel ID entered string Y e.g. "open:10"
playerId Account identifier entered in the channel
Hive player ID
long Y e.g. 1234
extraData User additional information (UTF-8 standard)
(maximum 256 Byte)
string Y e.g. "abcd"
timestamp Date and time entered in the channel (UTC+0 standard, yyyy-MM-dd'T'HH:mm:ss.SSSZ format) string Y e.g. "2024-11-12T08:59:59.497Z"

Sample

{
  "packetType": "NOTIFY_ENTER_CHANNEL",
  "body": {
    "gameIndex": 1,
    "channelId": "open:10",
    "playerId": 1234,
    "extraData": "abcd",
    "timestamp": "2024-11-12T08:59:59.497Z"
  }
}

Channel exit message

Field Name Description Type Required
packetType Channel exit message (NOTIFY_EXIT_CHANNEL) string Y
body Request data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
channelId Exited channel ID string Y e.g. "open:10"
playerId Identifier of the account that exited the channel
Hive player ID
long Y e.g. 2222
extraData User additional information (UTF-8 based)
(maximum 256 Byte)
string Y e.g. "abcd"
timestamp Date and time of exit from the channel (UTC+0 based, format yyyy-MM-dd'T'HH:mm:ss.SSSZ) string Y e.g. "2024-11-12T08:59:59.497Z"

Sample

{
  "packetType": "NOTIFY_EXIT_CHANNEL",
  "body": {
    "gameIndex": 1,
    "channelId": "open:10",
    "playerId": 2222,
    "extraData": "abcd",
    "timestamp": "2024-11-12T09:29:35.872Z"
  }
}

Channel Deletion Message

Field Name Description Type Required
packetType Channel deletion message (NOTIFY_DELETE_CHANNEL) string Y
body Request data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
channelId Deleted channel ID string Y e.g. "open:10"
timestamp Time of channel deletion (based on UTC+0, format yyyy-MM-dd'T'HH:mm:ss.SSSZ) string Y e.g. "2024-11-12T08:59:59.497Z"

Sample

{
  "packetType": "NOTIFY_DELETE_CHANNEL",
  "body": {
    "gameIndex": 1,
    "channelId": "owner:1",
    "timestamp": "2024-11-13T05:06:29.198Z"
  }
}

Channel Announcement Message

Field Name Description Type Required
packetType Notification message (NOTIFY_CHANNEL_NOTICE) string Y
body Request data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
channelId Channel ID that received the notification message string N e.g. "open:10"
from Identifier of the account that sent the notification message string Y e.g. SYSTEM
message Content of the notification message string Y e.g. "This is a notification message."
timestamp Date and time the notification message was sent (UTC+0 standard, format yyyy-MM-dd'T'HH:mm:ss.SSSZ) string Y e.g. "2024-11-13T05:06:29.198Z"

Sample

// Announce to specific channel
{
  "packetType": "NOTIFY_CHANNEL_NOTICE",
  "body": {
    "gameIndex": 1,
    "channelId": "open:10",
    "from": "SYSTEM",
    "message": "This is an announcement message.",
    "timestamp": "2024-11-13T05:06:29.198Z"
  }
}

Channel Message

Field Name Description Type Required
packetType Channel message (NOTIFY_CHANNEL_CHAT) string Y
body Request data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
from Identifier of the account that sent the channel message
Hive player ID
long Y e.g. 2222
fromExtra User additional information (UTF-8 based)
(up to 256 Byte)
string Y e.g. "bbbb"
to Channel ID that sent the channel message string Y e.g. "open:10"
langCode Hive language code
(based on ISO 639 alpha-2, languages not distinguished by ISO 639 alpha-2 should be separated with a Script tag)
string Y e.g. "ko"
timestamp Date and time when the channel message was sent (UTC+0 based, format yyyy-MM-dd'T'HH:mm:ss.SSSZ) string Y e.g. "2024-11-13T05:12:18.385Z"

Sample

{
  "packetType": "NOTIFY_CHANNEL_CHAT",
  "body": {
    "gameIndex": 1,
    "from": 2222,
    "fromExtra": "bbbb",
    "to": "open:10",
    "message": "Hello World!",
    "langCode": "ko",
    "timestamp": "2024-11-13T05:12:18.385Z"
  }
}

1:1 Message

Field Name Description Type Required
packetType 1:1 Message (NOTIFY_DIRECT_CHAT) string Y
body Request Data object Y

Body

Field Name Description Type Required Example
gameIndex Hive game index integer Y e.g. 1
from Identifier of the account that received the 1:1 message
Hive player ID
long Y e.g. 1234
fromExtra User additional information (UTF-8 based)
(maximum 256 Byte)
string Y e.g. "abcd"
to Identifier of the account that sent the 1:1 message
Hive player ID
long Y e.g. 2222
message Content of the 1:1 message string Y e.g. "Hello. This is a 1:1 chat."
langCode Hive language code
(based on ISO 639 alpha-2, languages not distinguished by ISO 639 alpha-2 are separated by Script tag)
string Y e.g. "ko"
timestamp Date and time when the 1:1 message was sent (UTC+0 based, format yyyy-MM-dd'T'HH:mm:ss.SSSZ) string Y e.g. "2024-11-13T05:12:50.060Z"

Sample

{
  "packetType": "NOTIFY_DIRECT_CHAT",
  "body": {
    "gameIndex": 1,
    "from": 1234,
    "fromExtra": "abcd",
    "to": 2222,
    "message": "Hello. This is 1:1 chat.",
    "langCode": "ko",
    "timestamp": "2024-11-13T05:12:50.060Z"
  }
}