MessagingService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스
복제되지 않음

메시징 서비스 는 동일한 경험의 서버가 토픽을 사용하여 실시간으로 서로 통신할 수 있도록 허용합니다(1초 미만).주제는 서버가 메시지를 보내고 받는 데 사용하는 개발자 정의 문자열(1–80자)입니다.

배달은 최선의 노력이지만 보장되지 않습니다. 배달 실패가 치명적이지 않도록 경험을 설계하십시오.

교차 서버 메시징은 서버 간에 더 자세하게 통신하는 방법을 살펴봅니다.

라이브 게임 서버에 임시 메시지를 게시하려면 Open Cloud API를 사용할 수 있습니다.

제한

이러한 제한은 변경될 수 있습니다.


<th>최대</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<b>메시지 크기</b>
</td>
<td>
1kB
</td>
</tr>
<tr>
<td>
<b>게임 서버당 전송되는 메시지</b>
</td>
<td>
분당 600 + 240 \* (이 게임 서버의 플레이어 수)
</td>
</tr>
<tr>
<td>
<b>토픽당 받은 메시지</b>
</td>
<td>
(40 + 80 \* 서버 수) 분당
</td>
</tr>
<tr>
<td>
<b>전체 게임에 대한 메시지 수신</b>
</td>
<td>
(400 + 200 \* 서버 수) 분당
</td>
</tr>
<tr>
<td>
<b>게임 서버당 허용되는 구독</b>
</td>
<td>
20 + 8 \* (이 게임 서버의 플레이어 수)
</td>
</tr>
<tr>
<td>
<b>게임 서버당 구독 요청</b>
</td>
<td>
분당 240 요청
</td>
</tr>
</tbody>
제한

속성

메서드

PublishAsync

()
생성

이 함수는 제공된 메시지를 토픽의 모든 구독자에게 보내 등록된 콜백을 트리거하고, 이를 호출합니다.

백엔드에서 메시지를 받을 때까지 생성됩니다.

매개 변수

topic: string

메시지가 발송되는 위치를 결정합니다.

기본값: ""
message: Variant

메시지에 포함할 데이터.

기본값: ""

반환

()

SubscribeAsync

생성

이 함수는 지정된 주제를 듣기 시작하기 위한 콜백을 등록합니다.콜백은 토픽이 메시지를 받을 때 호출됩니다.동일한 주제에 대해 여러 번 호출할 수 있습니다.

콜백

콜백은 단일 인수로 호출되며 다음 항목이 포함된 테이블입니다.


<th>요약</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<b>데이터</b>
</td>
<td>
개발자가 페이로드를 제공했음
</td>
</tr>
<tr>
<td>
<b>보냄</b>
</td>
<td>
메시지가 전송된 시간(초) Unix 시간 in seconds at which the message was sent
</td>
</tr>
</tbody>
필드

구독이 올바르게 등록될 때까지 생성되며 연결 개체를 반환합니다.

구독을 취소하려면 반환된 개체에서 Disconnect()를 호출하십시오.한 번 호출되면 콜백은 결코 호출되어서는 안됩니다.연결이 포함된 스크립트를 처리하면 기본 연결도 취소됩니다.

또한 제공된 메시지를 토픽의 모든 구독자에게 보내 등록된 콜백을 트리거하는 MessagingService:PublishAsync()를 참조하십시오.

매개 변수

topic: string

메시지를 수신할 위치를 결정합니다.

기본값: ""
callback: function

메시지가 받힐 때마다 호출되는 함수.

기본값: ""

반환

토픽에서 구독을 취소할 수 있는 연결.

코드 샘플

This example demonstrates how to use MessagingService:SubscribeAsync() to listen to a topic for cross-server chat within a game universe.

When a player joins, the example subscribes to the topic player-<player.UserId>. When a message is sent with this topic, the connected callback executes and prints Received message for <player.Name">. It also disconnects the connection when the player's ancestry changes.

In order for this to work as expected it must be placed in a server Script.

Subscribing to Cross Server Messages

local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
--subscribe to the topic
local topic = "player-" .. player.UserId
local connection = MessagingService:SubscribeAsync(topic, function(message)
print("Received message for", player.Name, message.Data)
end)
player.AncestryChanged:Connect(function()
-- unsubscribe from the topic
connection:Disconnect()
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)

이벤트