コード例 #1
0
        public void StartClient(string address, int port)
        {
            // Connect to a remote device.
            try
            {
                IPAddress ip = IPAddress.Parse(address);

                IPEndPoint remoteEP = new IPEndPoint(ip, port);

                if (socket != null)
                // Create a TCP/IP socket.
                {
                    if (socket.Connected == true)
                    {
                        //이미 접속은 했는데 로그인 실패면 다시 한다.
                        if (User.LoginSuccess == true)
                        {
                            return;
                        }
                    }

                    socket.Dispose();
                    socket = null;
                    socket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);
                }
                else
                {
                    socket = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);
                }


                socket.ReceiveTimeout = 200;
                socket.SendTimeout    = 2000;

                User.LoginSuccess = false;

                var mainpage = (MainPage)Application.Current.MainPage;


                var result = socket.BeginConnect(remoteEP, null, null);

                bool success = result.AsyncWaitHandle.WaitOne(500, true);
                if (success)
                {
                    socket.EndConnect(result);
                }

                if (socket.Connected == true)
                {
                    NetProcess.SendVersion();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: blessnhs/blessnhs
        void OnTapped(object sender, EventArgs e)
        {
            try
            {
                var sndObject = sender as StackLayout;
                var grid      = this.Parent as Grid;

                switch (sndObject.StyleId)
                {
                case "RegCamera":
                {
                    var    machineid = DependencyService.Get <MethodExt>().MachineId();
                    string Model     = DeviceInfo.Model;
                    NetProcess.SendRegCamera(Model, machineid);

                    PopupNavigation.Instance.PushAsync(new CameraPage());
                }
                break;

                case "MyCamera":
                {
                    rewardVideo.ShowAd();
                    NetProcess.SendReqCameraList();
                }
                break;

                case "Qna":
                {
                    iIterstitia.ShowAd();
                    PopupNavigation.Instance.PushAsync(new QnAPage());
                }
                break;

                case "Setting":
                {
                    PopupNavigation.Instance.PushAsync(new SettingPage());
                }
                break;
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: blessnhs/blessnhs
 private void NetworkProcess()
 {
     //network
     {
         //network thread
         Task.Run(() =>
         {
             while (true)
             {
                 try
                 {
                     NetProcess.start();
                     NetProcess.client.PacketRecvSync();
                     NetProcess.Loop();
                 }
                 catch (Exception e)
                 {
                 }
             }
         });
     }
 }
コード例 #4
0
        static public void Loop()
        {
            if (client.socket == null || client.socket.Connected == false)
            {
                return;
            }

            CompletePacket data;

            if (client.PacketQueue.TryDequeue(out data) == true)
            {
                try
                {
                    switch (data.Protocol)
                    {
                    case (int)PROTOCOL.IdPktVersionRes:
                    {
                        VERSION_RES res = new VERSION_RES();
                        res = VERSION_RES.Parser.ParseFrom(data.Data);

                        var currentVersion = VersionTracking.CurrentVersion;

                        double myversion;
                        if (double.TryParse(currentVersion, out myversion) == false)
                        {
                        }

                        const Double Eps = 0.000000000000001;

                        User.Version = res.VarVersion;

                        if (Math.Abs(res.VarVersion - myversion) > Eps)
                        {
                            //첫 검수라 임시 주석 2번째 패치 부터는 활성화
                            if (Device.RuntimePlatform == Device.Android && User.OnceVersionNotify == false)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        User.OnceVersionNotify = true;
                                        DependencyService.Get <MethodExt>().Notification("New Version Updated");
                                    });
                            }
                        }

                        SQLLiteDB.LoadCacheData();
                        if (User.NickName != null)
                        {
                            NetProcess.SendLogin(User.Uid, User.Token);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktLoginRes:
                    {
                        LOGIN_RES res = new LOGIN_RES();
                        res = LOGIN_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Xamarin.Forms.DependencyService.Register <MethodExt>();

                            DependencyService.Get <MethodExt>().Notification("New Version Updated");

                            User.LoginSuccess = true;
                            SQLLiteDB.Upsert(res.VarName, "");

                            if (PopupNavigation.Instance.PopupStack.Count > 0)
                            {
                                PopupNavigation.Instance.PopAsync();
                            }
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                });

                            User.LoginSuccess = false;
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomListRes:
                    {
                        ROOM_LIST_RES res = new ROOM_LIST_RES();
                        res = ROOM_LIST_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktNoticeRes:
                    {
                        NOTICE_RES res = new NOTICE_RES();
                        res = NOTICE_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRegCameraRes:
                    {
                        REG_CAMERA_RES res = new REG_CAMERA_RES();
                        res = REG_CAMERA_RES.Parser.ParseFrom(data.Data);

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktCameraListRes:
                    {
                        CAMERA_LIST_RES res = new CAMERA_LIST_RES();
                        res = CAMERA_LIST_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode == ErrorCode.Success)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;

                                    PopupNavigation.Instance.PushAsync(new CameraListPage(res.VarCamera));
                                });
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktMailListRes:
                    {
                        MAIL_LIST_RES res = new MAIL_LIST_RES();
                        res = MAIL_LIST_RES.Parser.ParseFrom(data.Data);
                    }
                    break;

                    case (int)PROTOCOL.IdPktPrayMessageRes:
                    {
                    }
                    break;

                    case (int)PROTOCOL.IdPktCameraWakeUpRes:
                    {
                        CAMERA_WAKE_UP_RES res = new CAMERA_WAKE_UP_RES();
                        res = CAMERA_WAKE_UP_RES.Parser.ParseFrom(data.Data);

                        TargetPlayerId.Add(res.VarToPlayerId);

                        if (PopupNavigation.Instance.PopupStack.Count == 0)
                        {
                            PopupNavigation.Instance.PushAsync(new CameraPage());
                        }
                        else
                        {
                            if (PopupNavigation.Instance.PopupStack[0].GetType() != typeof(CameraPage))
                            {
                                PopupNavigation.Instance.PopAsync();
                                PopupNavigation.Instance.PushAsync(new CameraPage());
                            }
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktStopStreamRes:
                    {
                        STOP_STREAM_RES res = new STOP_STREAM_RES();
                        res = STOP_STREAM_RES.Parser.ParseFrom(data.Data);

                        TargetPlayerId.Remove(res.VarToPlayerId);
                    }
                    break;

                    case (int)PROTOCOL.IdPktCreateRoomRes:
                    {
                        CREATE_ROOM_RES res = new CREATE_ROOM_RES();
                        res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;


                                User.RoomIdList.Add(res.VarRoomId);

                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktEnterRoomRes:
                    {
                        ENTER_ROOM_RES res = new ENTER_ROOM_RES();
                        res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data);

                        if (res.VarCode != ErrorCode.DuplicateEnterRoom && res.VarCode != ErrorCode.Success)
                        {
                            break;
                        }

                        Device.BeginInvokeOnMainThread(() =>
                            {
                                try
                                {
                                    var mainpage = (MainPage)Application.Current.MainPage;
                                }
                                catch (Exception e)
                                {
                                }
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktRoomPassThroughRes:
                    {
                        ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES();
                        res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data);
                        Device.BeginInvokeOnMainThread(() =>
                            {
                                var mainpage = (MainPage)Application.Current.MainPage;
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktLeaveRoomRes:
                    {
                        LEAVE_ROOM_RES res = new LEAVE_ROOM_RES();
                        res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;

                        Device.BeginInvokeOnMainThread(() =>
                            {
                            });
                    }
                    break;

                    case (int)PROTOCOL.IdPktAudioMessageRes:
                    {
                        AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES();
                        res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.pos    = res.VarPos;
                            AudioStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktBitmapMessageRes:
                    {
                        BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES();
                        res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            JpegStream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktMpeg2TsMessageRes:
                    {
                        MPEG2TS_MESSAGE_RES res = new MPEG2TS_MESSAGE_RES();
                        res = MPEG2TS_MESSAGE_RES.Parser.ParseFrom(data.Data);

                        foreach (var msg in res.VarMessage)
                        {
                            StreamWrapper wra = new StreamWrapper();
                            wra.stream = new MemoryStream(msg.ToByteArray());
                            wra.type   = res.VarType;
                            Mpeg2Stream.Enqueue(wra);
                        }
                    }
                    break;

                    case (int)PROTOCOL.IdPktNewUserInRoomNty:
                    {
                        NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY();
                        res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data);

                        var mainpage = (MainPage)Application.Current.MainPage;
                    }
                    break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
        }