本文整理汇总了C#中ConnectionProtocol类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionProtocol类的具体用法?C# ConnectionProtocol怎么用?C# ConnectionProtocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionProtocol类属于命名空间,在下文中一共展示了ConnectionProtocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChatPeer
public ChatPeer(IPhotonPeerListener listener, ConnectionProtocol protocol) : base(listener, protocol)
{
#if UNITY
#pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
if (PhotonPeer.NoSocket)
{
#if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
UnityEngine.Debug.Log("Using class SocketUdpNativeDynamic");
this.SocketImplementation = typeof(SocketUdpNativeDynamic);
#elif !UNITY_EDITOR && UNITY_IPHONE
UnityEngine.Debug.Log("Using class SocketUdpNativeStatic");
this.SocketImplementation = typeof(SocketUdpNativeStatic);
#elif !UNITY_EDITOR && (UNITY_WINRT)
// this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
#else
Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
this.SocketImplementation = udpSocket;
if (udpSocket == null)
{
UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
}
#endif
if (this.SocketImplementation == null)
{
UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
}
}
#pragma warning restore 0162
if (protocol == ConnectionProtocol.WebSocket || protocol == ConnectionProtocol.WebSocketSecure) {
UnityEngine.Debug.Log("Using SocketWebTcp");
this.SocketImplementation = Type.GetType("ExitGames.Client.Photon.SocketWebTcp, Assembly-CSharp");//typeof(SocketWebTcp);
}
#endif
}
示例2: NetworkingPeer
public NetworkingPeer(IPhotonPeerListener listener, string playername, ConnectionProtocol connectionProtocol)
: base(listener, connectionProtocol)
{
#if UNITY_EDITOR || (!UNITY_IPHONE && !UNITY_ANDROID && !UNITY_PS3)
Debug.Log("Using C# Socket");
this.SocketImplementation = typeof(SocketUdp);
#elif !UNITY_EDITOR && UNITY_PS3
Debug.Log("Using class SocketUdpNativeDllImport");
this.SocketImplementation = typeof(SocketUdpNativeDllImport);
#elif !UNITY_EDITOR && UNITY_ANDROID
Debug.Log("Using class SocketUdpNativeDynamic");
this.SocketImplementation = typeof(SocketUdpNativeDynamic);
#elif !UNITY_EDITOR && UNITY_IPHONE
Debug.Log("Using class SocketUdpNativeStatic");
this.SocketImplementation = typeof(SocketUdpNativeStatic);
#endif
this.Listener = this;
// don't set the field directly! the listener is passed on to other classes, which get updated by the property set method
this.externalListener = listener;
this.PlayerName = playername;
this.mLocalActor = new PhotonPlayer(true, -1, this.playername);
this.AddNewPlayer(this.mLocalActor.ID, this.mLocalActor);
// RPC shortcut lookup creation (from list of RPCs, which is updated by Editor scripts)
rpcShortcuts = new Dictionary<string, int>(PhotonNetwork.PhotonServerSettings.RpcList.Count);
for (int index = 0; index < PhotonNetwork.PhotonServerSettings.RpcList.Count; index++)
{
var name = PhotonNetwork.PhotonServerSettings.RpcList[index];
rpcShortcuts[name] = index;
}
this.State = global::PeerState.PeerCreated;
}
示例3: SessionData
public SessionData(string sessionName, string hostName, int port, ConnectionProtocol protocol, string sessionConfig)
{
SessionName = sessionName;
Host = hostName;
Port = port;
Proto = protocol;
PuttySession = sessionConfig;
}
示例4: Connect
public bool Connect(string address, ConnectionProtocol protocol)
{
if (this.UsedProtocol != protocol)
{
return false;
}
return true;
}
示例5: TestClient
/// <summary>
/// Initializes a new instance of the <see cref = "TestClient" /> class.
/// </summary>
public TestClient(ConnectionProtocol connectionProtocol)
{
this.autoResetEventInit = new AutoResetEvent(false);
this.OperationResponseQueue = new Queue<OperationResponse>(1000);
this.EventQueue = new Queue<EventData>(1000);
this.PhotonClient = new LoadBalancingPeer(this, connectionProtocol) { DebugOut = DebugLevel.INFO };
this.fiber.Start();
}
示例6: LoadbalancingOnlineTests
public LoadbalancingOnlineTests(string schemeName, ConnectionProtocol protocol)
: base(new OnlineConnectPolicy(GetAuthScheme(schemeName), protocol))
{
if (schemeName == "TokenLessAuthForOldClients" || schemeName == "TokenAuthNoUserIds")
{
this.Player1 = null;
this.Player2 = null;
this.Player3 = null;
}
}
示例7: OnlineNUnitClient
/// <summary>
/// Initializes a new instance of the <see cref = "OnlineNUnitClient" /> class.
/// </summary>
public OnlineNUnitClient(ConnectionProtocol connectionProtocol, bool logPhotonClientMessages = false)
{
this.Id = Interlocked.Increment(ref curentId);
this.LogPhotonClientMessages = logPhotonClientMessages;
this.autoResetEventInit = new AutoResetEvent(false);
this.OperationResponseQueue = new Queue<OperationResponse>(1000);
this.EventQueue = new Queue<EventData>(1000);
this.Peer = new PhotonPeer(this, connectionProtocol) { DebugOut = DebugLevel.INFO };
this.fiber.Start();
}
示例8: GetPolicy
public static ConnectPolicy GetPolicy(string policyName, ConnectionProtocol protocol)
{
switch (policyName)
{
case "DEV":
// return new OnlineConnectPolicy(new TokenAuthenticationScheme(), protocol)
case "LIVE":
// return new OnlineConnectPolicy(new TokenAuthenticationScheme(), protocol);
case "LOCAL":
default:
return new OnlineConnectPolicy(new TokenAuthenticationScheme(), protocol);
}
}
示例9: Start
public static Process Start(string serverAddress, string appId, ConnectionProtocol protocol, string photonCmdLine, string relativeWorkingDirectory)
{
if (CheckConnection(serverAddress, appId, protocol))
{
return null;
}
if (!IsLocalAddress(serverAddress))
{
throw new Exception(string.Format((string) "failed to establish connection to {0} using protocol {1}", serverAddress, protocol));
}
var path = FindPhoton();
Environment.CurrentDirectory += relativeWorkingDirectory;
return StartPhoton(serverAddress, appId, protocol, path, photonCmdLine);
}
示例10: NetworkingPeer
public NetworkingPeer(IPhotonPeerListener listener, string playername, ConnectionProtocol connectionProtocol)
: base(listener, connectionProtocol)
{
this.Listener = this;
// don't set the field directly! the listener is passed on to other classes, which get updated by the property set method
this.externalListener = listener;
this.PlayerName = playername;
this.mLocalActor = new PhotonPlayer(true, -1, this.playername);
this.AddNewPlayer(this.mLocalActor.ID, this.mLocalActor);
// RPC shortcut lookup creation (from list of RPCs, which is updated by Editor scripts)
rpcShortcuts = new Dictionary<string, int>(PhotonNetwork.PhotonServerSettings.RpcList.Count);
for (int index = 0; index < PhotonNetwork.PhotonServerSettings.RpcList.Count; index++)
{
var name = PhotonNetwork.PhotonServerSettings.RpcList[index];
rpcShortcuts[name] = index;
}
this.State = global::PeerState.PeerCreated;
}
示例11: CheckConnection
private static bool CheckConnection(string serverAddress, string appId, ConnectionProtocol protocol)
{
var listner = new PhotonListener(false);
var peer = new PhotonPeer(listner, protocol);
if (!peer.Connect(serverAddress, appId))
{
return false;
}
var counter = 100;
while (--counter > 0)
{
peer.Service();
if (listner.WaitForConnection(0))
{
var res = peer.PeerState == PeerStateValue.Connected;
peer.Disconnect();
return res;
}
Thread.Sleep(50);
}
return false;
}
示例12: LitePeer
/// <summary>
/// Creates a LitePeer instance to communicate with Photon with your selection of protocol.
/// We recommend UDP.
/// </summary>
/// <param name="listener">Your IPhotonPeerListener implementation.</param>
/// <param name="protocolType">Protocol to use to connect to Photon.</param>
public LitePeer(IPhotonPeerListener listener, ConnectionProtocol protocolType) : base(listener, protocolType)
{
}
示例13: OpAuthenticateOnce
/// <summary>
/// Sends this app's appId and appVersion to identify this application server side.
/// This is an async request which triggers a OnOperationResponse() call.
/// </summary>
/// <remarks>
/// This operation makes use of encryption, if that is established before.
/// See: EstablishEncryption(). Check encryption with IsEncryptionAvailable.
/// This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).
/// </remarks>
/// <param name="appId">Your application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).</param>
/// <param name="appVersion">The client's version (clients with differing client appVersions are separated and players don't meet).</param>
/// <param name="authValues">Optional authentication values. The client can set no values or a UserId or some parameters for Custom Authentication by a server.</param>
/// <param name="regionCode">Optional region code, if the client should connect to a specific Photon Cloud Region.</param>
/// <param name="encryptionMode"></param>
/// <param name="expectedProtocol"></param>
/// <returns>If the operation could be sent (has to be connected).</returns>
public virtual bool OpAuthenticateOnce(string appId, string appVersion, AuthenticationValues authValues, string regionCode, EncryptionMode encryptionMode, ConnectionProtocol expectedProtocol)
{
if (this.DebugOut >= DebugLevel.INFO)
{
this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
}
var opParameters = new Dictionary<byte, object>();
// shortcut, if we have a Token
if (authValues != null && authValues.Token != null)
{
opParameters[ParameterCode.Secret] = authValues.Token;
return this.OpCustom(OperationCode.AuthenticateOnce, opParameters, true, (byte)0, false); // we don't have to encrypt, when we have a token (which is encrypted)
}
if (encryptionMode == EncryptionMode.DatagramEncryption && expectedProtocol != ConnectionProtocol.Udp)
{
Debug.LogWarning("Expected protocol set to UDP, due to encryption mode DatagramEncryption. Changing protocol in PhotonServerSettings from: " + PhotonNetwork.PhotonServerSettings.Protocol);
PhotonNetwork.PhotonServerSettings.Protocol = ConnectionProtocol.Udp;
expectedProtocol = ConnectionProtocol.Udp;
}
opParameters[ParameterCode.ExpectedProtocol] = (byte)expectedProtocol;
opParameters[ParameterCode.EncryptionMode] = (byte)encryptionMode;
opParameters[ParameterCode.AppVersion] = appVersion;
opParameters[ParameterCode.ApplicationId] = appId;
if (!string.IsNullOrEmpty(regionCode))
{
opParameters[ParameterCode.Region] = regionCode;
}
if (authValues != null)
{
if (!string.IsNullOrEmpty(authValues.UserId))
{
opParameters[ParameterCode.UserId] = authValues.UserId;
}
if (authValues.AuthType != CustomAuthenticationType.None)
{
opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
if (!string.IsNullOrEmpty(authValues.Token))
{
opParameters[ParameterCode.Secret] = authValues.Token;
}
else
{
if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
{
opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthGetParameters;
}
if (authValues.AuthPostData != null)
{
opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
}
}
}
}
return this.OpCustom(OperationCode.AuthenticateOnce, opParameters, true, (byte)0, this.IsEncryptionAvailable);
}
示例14: OpRaiseEvent
private readonly Dictionary<byte, object> opParameters = new Dictionary<byte, object>(); // used in OpRaiseEvent() (avoids lots of new Dictionary() calls)
#endregion Fields
#region Constructors
/// <summary>
/// Creates a Peer with selected connection protocol.
/// </summary>
/// <remarks>Each connection protocol has it's own default networking ports for Photon.</remarks>
/// <param name="protocolType">The preferred option is UDP.</param>
public LoadBalancingPeer(ConnectionProtocol protocolType)
: base(protocolType)
{
// this does not require a Listener, so:
// make sure to set this.Listener before using a peer!
}
示例15: StartPhoton
private static Process StartPhoton(string serverAddress, string appId, ConnectionProtocol protocol, string path, string photonCmdLine)
{
var process = Process.Start(path, photonCmdLine);
if (process == null)
{
throw new Exception("PhotonSocketServer.exe can not be started");
}
if (process.WaitForExit(6500))
{
throw new Exception(string.Format("'{0}' finished unexpectedly.", path));
}
// we try to connect to new process
var count = 15;
while (count-- > 0)
{
if (CheckConnection(serverAddress, appId, protocol))
{
return process;
}
if (process.WaitForExit(1000))
{
process.Close();
throw new Exception(string.Format("'{0}' finished unexpectedly", path));
}
}
process.CloseMainWindow();
if (!process.WaitForExit(1000))
{
process.Kill();
}
process.Close();
throw new Exception(string.Format("Unable to connect to address={1} and process {0}", path, serverAddress));
}