设为首页 收藏本站
查看: 697|回复: 0

[经验分享] Photon Server伺服务器在LoadBalancing的基础上扩展登陆服务

[复制链接]

尚未签到

发表于 2017-12-8 08:11:16 | 显示全部楼层 |阅读模式
  一,如何创建一个Photon Server服务
  参见此博客 快速了解和使用Photon Server
  二, 让LoadBalancing与自己的服务一起启动
  原Photonserver.config文件中需要改动的地方有4处
  1.  <UDPListeners> 标签
  Udp监听端口



      <UDPListeners>
<UDPListener
IPAddress="0.0.0.0"
Port="5055"
OverrideApplication="Master">
</UDPListener>
<UDPListener
IPAddress="0.0.0.0"
Port="5056"
OverrideApplication="Game">
</UDPListener>
<UDPListener
IPAddress="0.0.0.0"
Port="5057"
OverrideApplication="LoginServer">
</UDPListener>
</UDPListeners>

  这里配置我自己的服务 LoginServer 监听端口为5057 所以Unity中链接服务器的端口也要改动


  address = "127.0.0.1:5057"; //连接本机ip,端口5055是Photon Lobalancing服务的默认端口
  Server = "LoginServer";
                peer = new PhotonPeer(this, ConnectionProtocol.Udp); //默认使用udp协议
                peer.Connect(address, Server);  
  2.  <TCPListeners> 标签
  TCP监控端口
  同样的添加配置    



<TCPListener
IPAddress="0.0.0.0"
Port="4532"
OverrideApplication="LoginServer"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000">
</TCPListener>
  3.  <WebSocketListeners>
  WebSocket兼容监听    



<WebSocketListener
IPAddress="0.0.0.0"
Port="9092"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="LoginServer">
</WebSocketListener>
  4.  <Applications>标签
  保留Master Game 等原来的标签



<Applications Default="Master">
<Application
Name="LoginServer"
BaseDirectory="LoginServer"
Assembly="LoginServer"
Type="LoginServer.LoginServer"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config"
>
</Application>
.
              .
              .

</Applications>

  完整的Photonserver.config文件  


DSC0000.gif DSC0001.gif


<?xml version="1.0" encoding="Windows-1252"?>
<!--
(c) 2015 by Exit Games GmbH, http://www.exitgames.com
Photon server configuration file.
For details see the photon-config.pdf.
This file contains two configurations:
"LoadBalancing"
Loadbalanced setup for local development: A Master-server and a game-server.
Starts the apps: Game, Master, CounterPublisher
Listens: udp-port 5055, tcp-port: 4530, 843 and 943        

-->
<Configuration>
<!-- Multiple instances are supported. Each instance has its own node in the config file. -->
<LoadBalancing
MaxMessageSize="512000"
MaxQueuedDataPerPeer="512000"
PerPeerMaxReliableDataInTransit="51200"
PerPeerTransmitRateLimitKBSec="256"
PerPeerTransmitRatePeriodMilliseconds="200"
MinimumTimeout="5000"
MaximumTimeout="30000"
DisplayName="LoadBalancing (MyCloud)">
<!-- 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="Master">
</UDPListener>
<UDPListener
IPAddress="0.0.0.0"
Port="5056"
OverrideApplication="Game">
</UDPListener>
<UDPListener
IPAddress="0.0.0.0"
Port="5057"
OverrideApplication="LoginServer">
</UDPListener>
</UDPListeners>
<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->        
<TCPListeners>
<!-- TCP listener for Game clients on Master application -->
<TCPListener
IPAddress="0.0.0.0"
Port="4530"
OverrideApplication="Master"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000"
>
</TCPListener>
<TCPListener
IPAddress="0.0.0.0"
Port="4531"
OverrideApplication="Game"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000">
</TCPListener>
<TCPListener
IPAddress="0.0.0.0"
Port="4532"
OverrideApplication="LoginServer"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000">
</TCPListener>
<!-- DON'T EDIT THIS. TCP listener for GameServers on Master application -->
<TCPListener
IPAddress="0.0.0.0"
Port="4520">
</TCPListener>
</TCPListeners>
<!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943)  -->
<PolicyFileListeners>
<!-- multiple Listeners allowed for different ports -->
<PolicyFileListener
IPAddress="0.0.0.0"
Port="843"
PolicyFile="Policy\assets\socket-policy.xml">
</PolicyFileListener>
<PolicyFileListener
IPAddress="0.0.0.0"
Port="943"
PolicyFile="Policy\assets\socket-policy-silverlight.xml">
</PolicyFileListener>
</PolicyFileListeners>

<!-- WebSocket (and Flash-Fallback) compatible listener -->
<WebSocketListeners>
<WebSocketListener
IPAddress="0.0.0.0"
Port="9090"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="Master">
</WebSocketListener>
<WebSocketListener
IPAddress="0.0.0.0"
Port="9091"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="Game">
</WebSocketListener>
<WebSocketListener
IPAddress="0.0.0.0"
Port="9092"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="LoginServer">
</WebSocketListener>
</WebSocketListeners>
<!-- 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="Master">
<Application
Name="LoginServer"
BaseDirectory="LoginServer"
Assembly="LoginServer"
Type="LoginServer.LoginServer"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config"
>
</Application>
<Application
Name="Master"
BaseDirectory="LoadBalancing\Master"
Assembly="Photon.LoadBalancing"
Type="Photon.LoadBalancing.MasterServer.MasterApplication"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config"
>
</Application>
<Application
Name="Game"
BaseDirectory="LoadBalancing\GameServer"
Assembly="Photon.LoadBalancing"
Type="Photon.LoadBalancing.GameServer.GameApplication"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
<!-- CounterPublisher Application -->
<Application
Name="CounterPublisher"
BaseDirectory="CounterPublisher"
Assembly="CounterPublisher"
Type="Photon.CounterPublisher.Application"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>   
</Applications>
</LoadBalancing>   
<!-- Instance settings -->
<MMoDemo
MaxMessageSize="512000"
MaxQueuedDataPerPeer="512000"
PerPeerMaxReliableDataInTransit="51200"
PerPeerTransmitRateLimitKBSec="256"
PerPeerTransmitRatePeriodMilliseconds="200"
MinimumTimeout="5000"
MaximumTimeout="30000"
DisplayName="MMO Demo"
>
<!-- 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="MMoDemo">
</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="MMoDemo"               
>
</TCPListener>
</TCPListeners>
<!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943)  -->
<PolicyFileListeners>
<!-- multiple Listeners allowed for different ports -->
<PolicyFileListener
IPAddress="0.0.0.0"
Port="843"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000">
</PolicyFileListener>
<PolicyFileListener
IPAddress="0.0.0.0"
Port="943"
PolicyFile="Policy\assets\socket-policy-silverlight.xml"
InactivityTimeout="10000">
</PolicyFileListener>
</PolicyFileListeners>
<!-- WebSocket (and Flash-Fallback) compatible listener -->
<WebSocketListeners>
<WebSocketListener
IPAddress="0.0.0.0"
Port="9090"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="MMoDemo">
</WebSocketListener>
</WebSocketListeners>
<!-- 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="MMoDemo">
<!-- MMO Demo Application -->
<Application
Name="MMoDemo"
BaseDirectory="MmoDemo"
Assembly="Photon.MmoDemo.Server"
Type="Photon.MmoDemo.Server.PhotonApplication"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
<!-- CounterPublisher Application -->
<Application
Name="CounterPublisher"
BaseDirectory="CounterPublisher"
Assembly="CounterPublisher"
Type="Photon.CounterPublisher.Application"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>   
</Applications>
</MMoDemo>

</Configuration>
View Code  unity 中使用 PhotonPeer 的时候要注意在销毁场景的时候关闭链接 peer.Disconnect();
  否则unity会在第二次运行的时候出现卡死的状态.
  PhotonPeer连接服务器的时候会创建一个网络线程,停止调试并不会自动的将这个线程结束,再次调试的时候Unity就会卡在PhotonPeer创建网络线程的操作上.......
  这是我的登陆服务

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-422012-1-1.html 上篇帖子: 实战之elasticsearch集群及filebeat server和logstash server 下篇帖子: webpack-dev-server配置指南(使用webpack3.0)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表