예제 #1
0
        public static bool SendPreconnectData(SDKConnection connection)
        {
            string Hello = "Pre-connect message";

            byte[] hello = new byte[1 + Hello.Length + 1];
            hello[0] = Constants.ID_ConnectionRebroadcast;

            for (int i = 0; i < Hello.Length; ++i)
            {
                hello[i + 1] = (byte)Hello[i];
            }
            hello[1 + Hello.Length] = 0;

            SDKResult result = connection.Send(hello);

            if (result.Failed())
            {
                Console.WriteLine("tonk_send 1 failed: ", result.ToString());
                return(false);
            }

            result = connection.Send(PreConnectData, PreConnectChannel);

            if (result.Failed())
            {
                Console.WriteLine("tonk_send 2 failed: ", result.ToString());
                return(false);
            }

            Console.WriteLine("Sent preconnect data");

            connection.Flush();
            return(true);
        }
예제 #2
0
        public static void LogTonkStatus(SDKConnection connection)
        {
            Tonk.Status   status   = connection.GetStatus();
            Tonk.StatusEx statusEx = connection.GetStatusEx();

            StringBuilder sb = new StringBuilder();

            sb.Append("tonk_status: ");
            if (status.Flags.HasFlag(Tonk.Flags.Initiated))
            {
                sb.Append("Initiated ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.TimeSync))
            {
                sb.Append("TimeSync ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.NATMap_Local))
            {
                sb.Append("NATMap_Local ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.NATMap_Remote))
            {
                sb.Append("NATMap_Remote ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.Connecting))
            {
                sb.Append("Connecting ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.Connected))
            {
                sb.Append("Connected ");
            }
            if (status.Flags.HasFlag(Tonk.Flags.Disconnected))
            {
                sb.Append("Disconnected ");
            }
            sb.AppendFormat(" RemoteId={0}", status.LocallyAssignedIdForRemoteHost);
            sb.AppendFormat(" AppBPS={0}", status.AppBPS);
            sb.AppendFormat(" ReliableQueueMsec={0}", status.ReliableQueueMsec);
            sb.AppendFormat(" LowPriQueueMsec={0}", status.LowPriQueueMsec);

            sb.AppendFormat(" ConnectionKey={0}", statusEx.ConnectionKey.ToString("X4"));
            sb.AppendFormat(" Local={0}", statusEx.Local.ToString());
            sb.AppendFormat(" Remote={0}", statusEx.Remote.ToString());
            sb.AppendFormat(" LocalNATPort={0}", statusEx.LocalNATMapExternalPort);
            sb.AppendFormat(" RemoteNATPort={0}", statusEx.RemoteNATMapExternalPort);
            sb.AppendFormat(" LocalId={0}", statusEx.RemoteAssignedIdForLocalHost);
            sb.AppendFormat(" PeerSeenBPS={0}", statusEx.PeerSeenBPS);
            sb.AppendFormat(" PeerSeenLossRate={0}", statusEx.PeerSeenLossRate);
            sb.AppendFormat(" PeerTripUsec={0}", statusEx.PeerTripUsec);
            sb.AppendFormat(" IncomingBPS={0}", statusEx.IncomingBPS);
            sb.AppendFormat(" PLR={0}", statusEx.IncomingLossRate);
            sb.AppendFormat(" TripUsec={0}", statusEx.TripUsec);

            Console.WriteLine(sb);
        }