コード例 #1
0
ファイル: Server.cs プロジェクト: marktabz/EncodeMe
        public static void Start()
        {
            if (_started)
            {
                return;
            }
            _started = true;

            NetworkComms.DisableLogging();

            var serializer = DPSManager.GetDataSerializer <ProtobufSerializer>();

            NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions(serializer,
                                                                            NetworkComms.DefaultSendReceiveOptions.DataProcessors, NetworkComms.DefaultSendReceiveOptions.Options);

            PeerDiscovery.EnableDiscoverable(PeerDiscovery.DiscoveryMethod.UDPBroadcast);

            NetworkComms.AppendGlobalIncomingPacketHandler <AndroidInfo>(AndroidInfo.GetHeader(), AndroidHandler.HandShakeHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StudentInfoRequest>(StudentInfoRequest.GetHeader(), AndroidHandler.StudentInfoRequested);
            NetworkComms.AppendGlobalIncomingPacketHandler <EndPointInfo>(EndPointInfo.GetHeader(), HandShakeHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetWork>(GetWork.GetHeader(), GetWorkHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Login>(Login.GetHeader(), LoginHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Logout>(Logout.GetHeader(), LogoutHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <SchedulesRequest>(SchedulesRequest.GetHeader(), AndroidHandler.ScheduleRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <EnrollRequest>(EnrollRequest.GetHeader(), AndroidHandler.EnrollRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <RegisterStudent>(RegisterStudent.GetHeader(), AndroidHandler.RegisterStudentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <SaveWork>(SaveWork.GetHeader(), SaveWorkHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetCourses>(GetCourses.GetHeader(), AndroidHandler.GetCoursesHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetCoursesDesktop>(GetCoursesDesktop.GetHeader(), GetCoursesHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Pong>(Pong.GetHeader(), PongHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <EnrollStudent>(EnrollStudent.GetHeader(), EnrollStudentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StartEnrollment>(StartEnrollment.GetHeader(), AndroidHandler.StartEnrollmentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <AddSchedule>(AddSchedule.GetHeader(), AndroidHandler.AddScheduleHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <CommitEnrollment>(CommitEnrollment.GetHeader(), AndroidHandler.CommitEnrollmentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StatusRequest>(StatusRequest.GetHeader(), AndroidHandler.StatusRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <CancelEnrollment>(CancelEnrollment.GetHeader(), AndroidHandler.CancelEnrollmentHandler);
            //  try
            // {
            Connection.StartListening(ConnectionType.UDP, new IPEndPoint(IPAddress.Any, 0), true);
            // }
            // catch (Exception e)
            // {
            //
            // }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: marktabz/EncodeMe
        private static AndroidInfo GetDeviceInfo()
        {
            var telephonyManager = (TelephonyManager)Application.Context.GetSystemService(Context.TelephonyService);
            var wifi             = (WifiManager)Application.Context.GetSystemService(Context.WifiService);
            var info             = new AndroidInfo();

            try
            {
                info.DeviceId = Build.Serial;
                info.Sim      = telephonyManager.Line1Number;
                info.Model    = Build.Brand;
            } catch (Exception) {}
            try
            {
                info.MAC      = wifi.ConnectionInfo.MacAddress;
                info.Hostname = Build.Model;
            } catch (Exception) {}

            return(info);
        }
コード例 #3
0
        public static void HandShakeHandler(PacketHeader packetheader, Connection connection,
                                            AndroidInfo ad)
        {
            var device = AndroidDevice.Cache.FirstOrDefault(x => x.IP == ad.IP);

            if (device == null)
            {
                device = new AndroidDevice();
            }

            device.IP       = ad.IP;
            device.Port     = ad.Port;
            device.DeviceId = ad.DeviceId;
            device.MAC      = ad.MAC;
            device.Model    = ad.Model;
            device.SIM      = ad.Sim;
            device.Save();

            var localEPs   = Connection.AllExistingLocalListenEndPoints();
            var serverInfo = new ServerInfo(Environment.MachineName);
            var ip         = new IPEndPoint(IPAddress.Parse(ad.IP), ad.Port);

            foreach (var localEP in localEPs[ConnectionType.UDP])
            {
                var lEp = localEP as IPEndPoint;

                if (lEp == null)
                {
                    continue;
                }
                if (!ip.Address.IsInSameSubnet(lEp.Address))
                {
                    continue;
                }

                serverInfo.IP   = lEp.Address.ToString();
                serverInfo.Port = lEp.Port;
                serverInfo.Send(ip);
                break;
            }
        }