【发布时间】:2021-12-31 23:56:35
【问题描述】:
所以,我一直在尝试使用 Photon Bolt 制作游戏,以在 PC 和 Android 设备之间建立连接。当在同一台计算机上连接两个游戏时,它工作正常,但如果我尝试连接两个不同的设备,无论是 PC 到 Android 连接还是 PC 到 PC,我开始遇到问题。在最好的情况下,连接需要很长时间(超时为 100000,连接超时为 5000,连接尝试 20 次),但大多数情况下它甚至没有连接。当客户端尝试连接时,消息 [NAT Punch] Ping [EndPoint IPv4 (my IP)] 开始出现在服务器日志上,但有时它会卡在 Attached [Entity [NetworkId 0-0-0-1-FF- FF-FF-FF] Photon.Bolt.PlatformState] (Token: NULL) 在客户端(PlatformState 是来自 Prefab 的状态,客户端在加载场景后实例化,客户端应该单击屏幕的某些部分来创建平台)。
这是启动服务器和客户端的代码(类似于入门教程一):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Matchmaking;
using UdpKit;
//using Udpkit;
public class MenuScript : Photon.Bolt.GlobalEventListener
{
void OnGUI(){
GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
if(GUILayout.Button("Start Server", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
BoltLauncher.StartServer();
}
if(GUILayout.Button("Start Client", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
//JoinSession();
BoltLauncher.StartClient();
}
GUILayout.EndArea();
}
public override void BoltStartDone(){
CreateServerSession();
}
public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
{
Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count);
foreach (var session in sessionList)
{
UdpSession photonSession = session.Value as UdpSession;
if (photonSession.Source == UdpSessionSource.Photon)
{
BoltMatchmaking.JoinSession(photonSession);
}
}
}
public void CreateServerSession(){
string matchName = "AB";
BoltMatchmaking.CreateSession(
sessionID:matchName,
sceneToLoad: "Level1"
);
}
public void JoinSession(){
if(BoltNetwork.IsRunning)
{
string id = "AB";
BoltMatchmaking.JoinSession(
sessionID: id
);
}
}
}
希望这就是所需的一切,我使用了两个 BoltGlobalBehavior 脚本,但我认为它们对那个问题并不重要(它们在服务器中实例化播放器,在客户端实例化平台)
【问题讨论】:
-
有防火墙吗?设备是否在同一网络上?你是如何告诉客户端服务器在哪里的
-
我已尝试停用我的电脑防火墙以尝试与我的手机在同一网络中使用该应用程序,但没有成功。在 SessionListUpdated 函数中,我应该搜索一个可用的 photonSession 并加入它的客户端。
标签: unity3d networking photon bolt