Skip to main content
Version: 7.0

Sending short data

LINE Planet provides APIs that let you send a limited size of data ("short data") to peers during communications. This page describes how to send and receive short data by call type.

Supported call typeSupported SDK version
1-to-1 call, group callAll versions

Common features

The following applies to sending short data regardless of call types.

Size limitation

The methods to send short data accept the type of the data along with the data itself. The maximum sizes for the data type and the data are as follows:

  • Data type: 100 bytes (including the null termination character)
  • Data: 800 bytes

Rate limit

Only one sending operation is allowed per second.

Retrieving the result of sending short data

Sometimes data transfer might fail even after several retries by LINE Planet. You can find out the result of data transfer asynchronously with the result handler callback.

1-to-1 call

In 1-to-1 calls, you can send and receive short data as follows.

Sending short data

To send short data to the call peer, use PlanetKitCall::SendShortData().

void SendShortDataExample(PlanetKit::PlanetKitCallPtr pCall, const std::wstring& wstrType, const std::string& strData)
{
pCall->SendShortData(wstrType.c_str(), (void*)strData.c_str(), (unsigned int)strData.size(), nullptr, [](void*, bool bSuccess, PlanetKit::ESendShortDataFailReason eReason) {
if (bSuccess) {
std::wcout << L"SendShortData succeeded" << std::endl;
} else {
std::wcout << L"SendShortData failed: " << (int)eReason << std::endl;
}
});
}

Handling received short data

The peer can receive the short data through ICallEvent::OnReceivedShortData.

class CallEventListener : public PlanetKit::ICallEvent {
public:
...

void OnReceivedShortData(PlanetKit::PlanetKitCallPtr pPlanetKitCall, PlanetKit::ShortDataParamPtr pShortDataParam) override {
// This is called when short data is received from the peer.
const wchar_t* pType = pShortDataParam->GetType();
const void* pData = pShortDataParam->GetData();
unsigned int nSize = pShortDataParam->GetSize();

std::string receivedData((const char*)pData, nSize);
std::wcout << L"Received short data: type=" << pType << L", data=";
std::cout << receivedData.c_str() << std::endl;
// Write your own code here to handle the received data.
}
}

Group call

In group calls, you can send short data to a specific peer or all peers.

Sending short data to a specific peer

To send short data to a specific peer, use PlanetKitConference::SendShortData().

void SendShortDataToSpecificPeerExample(PlanetKit::PlanetKitConferencePtr pConference, PlanetKit::UserIdPtr pPeerId, const std::wstring& wstrType, const std::string& strData)
{
pConference->SendShortData(wstrType.c_str(), (void*)strData.c_str(), (unsigned int)strData.size(), pPeerId, nullptr, [](void*, bool bSuccess, PlanetKit::ESendShortDataFailReason eReason) {
if (bSuccess) {
std::wcout << L"SendShortData to specific peer succeeded" << std::endl;
} else {
std::wcout << L"SendShortData failed: " << (int)eReason << std::endl;
}
});
}

Sending short data to all peers

To send short data to all peers, use PlanetKitConference::SendShortDataToAllPeers().

void SendShortDataToAllPeersExample(PlanetKit::PlanetKitConferencePtr pConference, const std::wstring& wstrType, const std::string& strData)
{
pConference->SendShortDataToAllPeers(wstrType.c_str(), (void*)strData.c_str(), (unsigned int)strData.size(), nullptr, [](void*, bool bSuccess, PlanetKit::ESendShortDataFailReason eReason) {
if (bSuccess) {
std::wcout << L"SendShortData to all peers succeeded" << std::endl;
} else {
std::wcout << L"SendShortData failed: " << (int)eReason << std::endl;
}
});
}

Handling received short data

The peers can receive the short data through IConferenceEvent::OnReceivedShortData.

class ConferenceEventListener : public PlanetKit::IConferenceEvent {
public:
...

void OnReceivedShortData(PlanetKit::PlanetKitConferencePtr pPlanetKitConference, PlanetKit::ShortDataParamPtr pParam) override {
// This is called when short data is received from a peer in the conference.
PlanetKit::UserIdPtr pSenderId = pParam->GetPeerID();
const wchar_t* pType = pParam->GetType();
const void* pData = pParam->GetData();
unsigned int nSize = pParam->GetSize();

std::string receivedData((const char*)pData, nSize);
std::wcout << L"Received short data from peer: type=" << pType << L", data=";
std::cout << receivedData.c_str() << std::endl;
// Write your own code here to handle the received data.
}
}

Failure reasons for sending short data

The ESendShortDataFailReason enum delivered by the result handler callback lets you determine the result of sending short data and its failure reason. The possible failure reasons are as follows:

ValueDescription
PLNK_SEND_SHORT_DATA_FAIL_REASON_NONEThe short data was sent successfully.
PLNK_SEND_SHORT_DATA_FAIL_REASON_INVALID_PARAMETEROne or more input parameters are invalid (e.g., data size is 0 or data pointer is NULL).
PLNK_SEND_SHORT_DATA_FAIL_REASON_TOO_LONG_DATA_TYPEThe data type exceeds the maximum allowed length (over 100 bytes including the null terminator).
PLNK_SEND_SHORT_DATA_FAIL_REASON_TOO_LONG_DATAThe data payload exceeds the maximum allowed size (over 800 bytes).
PLNK_SEND_SHORT_DATA_FAIL_REASON_TOO_FREQUENTThe short data was sent more frequently than allowed (rate limit exceeded). Only one sending operation is allowed per second.
PLNK_SEND_SHORT_DATA_FAIL_REASON_TIMEOUTThe sending operation failed due to a timeout.

APIs related to sending short data are as follows.

Common

Enums

1-to-1 call

Methods

Events

Group call

Methods

Events