PhotonServer
下载:https://www.photonengine.com/en-US/sdks#realtime
解压
打开deploy
根据电脑打开bin_Win32/bin_Win64
启动PhotonControl
创建服务器
在deploy文件夹中创建新文件夹
在新建的文件夹中创建新文件夹并取名为bin
打开VS,新建项目
可以删除class1
添加引用(浏览,找到上面解压的lib文件夹)
- ExitGames.Logging.Log4Net.dll
- log4net.dll
- Photon.SocketServer.dll
- ExitGamesLibs.dll
- PhotonHostRuntimeInterfaces.dll
创建类并公开
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestSever
{
public class TestSeverClass
{
}
}
将此类设为入口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon.SocketServer;
namespace TestSever
{
public class TestSeverClass : ApplicationBase
{
//有客户端连接时调用
protected override PeerBase CreatePeer(InitRequest initRequest)
{
PeerClass peer = new PeerClass(initRequest);
return peer;
}
//初始化时
protected override void Setup()
{
}
//关闭服务器时
protected override void TearDown()
{
}
}
}
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestSever
{
public class PeerClass : ClientPeer
{
public PeerClass(InitRequest initRequest):base(initRequest)
{
}
protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
{
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
}
}
}
修改输出路径
右击命名空间,选择属性,选择生成,修改输出路径,修改为前面自己创建的bin文件夹。
再次右击命名空间,选择生成
找到bin_Win64/bin_Win32中配置文件photonServer.config并打开(拖到VS即可)
在打开的XML文件中的<Configuration></Configuration>间写入下面节点(根据实际情况自行修改)并保存。
<TestSever
MaxMessageSize="512000"
MaxQueuedDataPerPeer="512000"
PerPeerMaxReliableDataInTransit="51200"
PerPeerTransmitRateLimitKBSec="256"
PerPeerTransmitRatePeriodMilliseconds="200"
MinimumTimeout="5000"
MaximumTimeout="30000"
DisplayName="TestSever"
>
<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
<!-- Port 5055 is Photon's default for UDP connections. -->
<UDPListeners>
<UDPListener
IPAddress="0.0.0.0"
Port="5055"
OverrideApplication="TestSever">
</UDPListener>
</UDPListeners>
<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
<!-- Port 4530 is Photon's default for TCP connecttions. -->
<!-- A Policy application is defined in case that policy requests are sent to this listener (known bug of some some flash clients) -->
<TCPListeners>
<TCPListener
IPAddress="0.0.0.0"
Port="4530"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000"
OverrideApplication="TestSever"
>
</TCPListener>
</TCPListeners>
<!-- Defines the Photon Runtime Assembly to use. -->
<Runtime
Assembly="PhotonHostRuntime, Culture=neutral"
Type="PhotonHostRuntime.PhotonDomainManager"
UnhandledExceptionPolicy="Ignore">
</Runtime>
<!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined. -->
<!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a "bin" folder. -->
<Applications Default="TestSever">
<!-- MMO Demo Application -->
<Application
Name="TestSever"
BaseDirectory="TestSever"
Assembly="TestSever"
Type="TestSever.TestSeverClass"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
</Applications>
</TestSever>
重新启动打开PhotonControl
即可看到自己添加的服务器。
选择此服务器后选择start as application即可启动。
选择stop application即停止。