public void CallbackConnectServer(object result) { if (ConnectionManager.Instance.IsConnected) { Deployment.Current.Dispatcher.BeginInvoke(() => { loadWorker.RunWorkerAsync(new LoadingArgument() { LoadingGrid = CreateLoadingGrid("ServerConnectPageConnecting"), LoadingType = LoadingTypes.Connection, Result = result }); }); //접속이 성공하고, 자동접속 설정이 On이면 자동접속을 위한 셋팅 if (SettingManager.Instance.SettingInfo.AutoConnect) { //접속된 서버 저장 ConnectionManager.Instance.SaveLastConnectedServer(PointingControlManager.Instance.DeviceType); } ServerExtraInfo srvExtraInfo = (ServerExtraInfo)result; //맥어드레스 저장 ConnectionManager.Instance.ConnectionInfo.CurrentServer.MacAddressList = srvExtraInfo.MacAddressList; ConnectionManager.Instance.ConnectionInfo.CurrentServer.LastDateTime = DateTime.Now; //접속 이력 저장 HistorygManager.Instance.Add(ConnectionManager.Instance.ConnectionInfo.CurrentServer); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show(I18n.GetString("AppMessageNotAbleConnectPC")); NavigationService.Navigate(ResourceUri.ServerListPageUri); }); } }
private void connectAppbarIconBtn_Click(object sender, EventArgs e) { //네트워크 연결체크 if (!NetworkUtils.IsNetworkAvailable) { NetworkUtils.ShowWiFiSettingPage(I18n.GetString("AppMessageRequiredDataNetwork"), I18n.GetString("AppMessageNotification")); return; } //현재 접속되어 있는 서버가 있다면 종료시킴. if (ConnectionManager.Instance.IsConnected) { ConnectionManager.Instance.DisconnectServer(null); } //선택된 서버 정보를 현재 서버로 변경 ServerInfo serverInfo = (ServerInfo)historyItemViewOnPage.SelectedItem; ConnectionManager.Instance.ConnectionInfo.CurrentServer = serverInfo; ConnectionManager.Instance.ConnectServer( SettingManager.Instance.SettingInfo.DeviceType, new CallbackHandler((object serverExtraInfo) => { Deployment.Current.Dispatcher.BeginInvoke(() => { if (serverExtraInfo is ServerExtraInfo) { ServerExtraInfo svrExtInfo = serverExtraInfo as ServerExtraInfo; AppStateUtils.Set(Constant.KEY_SERVER_EXTRA_INFO, svrExtInfo); this.NavigationService.GoBack(); } else if (serverExtraInfo is SocketError) { if ((SocketError)serverExtraInfo == SocketError.TimedOut) { MessageBox.Show(I18n.GetString("AppMessageNotAbleConnectPC")); (SearchPivot.Parent as Pivot).SelectedIndex = 0; } } else { MessageBox.Show(I18n.GetString("AppMessageAccessCodeIncorrect")); //접속코드 입력 화면으로 이동 this.NavigationService.Navigate(new Uri(string.Format(Constant.PAGE_SERVER_CONNECT, serverInfo.ServerName), UriKind.Relative)); } }); })); }
public static Object ResolveServerPacket(PacketTypes packetType, Object receivedObj) { SocketAsyncEventArgs args = receivedObj as SocketAsyncEventArgs; Object retObj = null; int offset = 0; int vsHeader = BitConverter.ToInt32(args.Buffer, offset); int pSize = BitConverter.ToInt32(args.Buffer, offset += Constant.INT_SIZE); //패킷 사이즈가 템플렛(헤더+사이즈+풋터) 보다 작으면 null 리턴 if (pSize < Constant.INT_SIZE * 3) { return(retObj); } int vsFooter = BitConverter.ToInt32(args.Buffer, pSize - Constant.INT_SIZE); Byte[] packet = new Byte[pSize - Constant.INT_SIZE * 3]; Buffer.BlockCopy(args.Buffer, offset += Constant.INT_SIZE, packet, 0, packet.Length); if (vsHeader == Constant.PACKET_VELOSTEP_HEADER && vsFooter == Constant.PACKET_VELOSTEP_FOOTER && pSize == args.BytesTransferred) { offset = 0; switch (packetType) { case PacketTypes.FindServer: ServerInfo serverInfo = new ServerInfo(); IPEndPoint remoteEndPoint = args.RemoteEndPoint as IPEndPoint; serverInfo.ServerIP = remoteEndPoint.Address.ToString(); serverInfo.UdpPort = remoteEndPoint.Port; serverInfo.TcpPort = BitConverter.ToInt32(packet, offset); serverInfo.ServerName = Encoding.UTF8.GetString(packet, offset += Constant.INT_SIZE, packet.Length - Constant.INT_SIZE); retObj = serverInfo; break; case PacketTypes.Coordinates: break; case PacketTypes.Authentication: ServerExtraInfo serverExtraInfo = null; //결과 bool로 파싱하지만 실제 길이는 INT_SIZE임. if (BitConverter.ToBoolean(packet, offset)) { byte[] macAddr = null; int keybdCount = BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); int macAddrCount = BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); List <KeyboardLayoutTypes> keyboardList = new List <KeyboardLayoutTypes>(); List <Byte[]> macAddrList = new List <Byte[]>(); //키보드 리스트 for (int i = 0; i < keybdCount; i++) { keyboardList.Add((KeyboardLayoutTypes)BitConverter.ToInt32(packet, offset += Constant.INT_SIZE)); } offset += Constant.INT_SIZE; //맥 주소 리스트 for (int i = 0; i < macAddrCount; i++) { macAddr = new byte[6]; Buffer.BlockCopy(packet, offset, macAddr, 0, macAddr.Length); macAddrList.Add(macAddr); offset += macAddr.Length; //for (int j=0; j<6; j++) // System.Diagnostics.Debug.WriteLine(string.Format("{0:X}-", macAddr[j])); } if (keybdCount > 0 || macAddrCount > 0) { serverExtraInfo = new ServerExtraInfo(); serverExtraInfo.KeyboardList = keyboardList; serverExtraInfo.MacAddressList = macAddrList; } } retObj = serverExtraInfo; break; case PacketTypes.RequestImage: break; case PacketTypes.DeviceMode: break; case PacketTypes.VirtualButton: break; case PacketTypes.AutoConnect: break; case PacketTypes.CheckConnection: ServerExtraInfo serverStatusInfo = null; int nRet = BitConverter.ToInt32(packet, offset); if (nRet == 1) { serverStatusInfo = new ServerExtraInfo(); serverStatusInfo.ScreenType = (ScreenTypes)BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); BitConverter.ToInt32(packet, offset += Constant.INT_SIZE); } retObj = serverStatusInfo; break; case PacketTypes.Keyboard: break; } } return(retObj); }
private void CheckConnectionThreadFn() { int batterySwitch = 1; int checkTime = 5000; //초기 5초 셋팅 while (true) { if (!NetworkUtils.IsNetworkAvailable) { if (ConnectionManager.Instance.IsConnected) { //접속중 WiFi가 연결이 끊긴경우 접속 해제 처리 UpdateConnectionStatus(false); } else if (AppStateUtils.ContainsRecoveryType(RecoveryTypes.Connection)) { //접속중 WiFi가 연결이 끊긴경우 접속 해제 처리 UpdateConnectionStatus(false); AppStateUtils.ClearRecoveryTypes(); } } else { //2. 커넥션 체크 (접속되었을때 체크시작, 접속해지후 체크종료) if (ConnectionManager.Instance.IsConnected) { checkTime = 3000; //체크 간격을 3초로 줄임 //쓰레드 대기 준비 connCheckDone.Reset(); //체크결과 요청 System.Net.Sockets.SocketError socketError = (System.Net.Sockets.SocketError)ConnectionManager.Instance.CheckConnection(SettingManager.Instance.SettingInfo, new CallbackHandler((object param) => { Deployment.Current.Dispatcher.BeginInvoke(() => { //쓰레드 재계 connCheckDone.Set(); if (ConnectionManager.Instance.IsConnected) { ServerExtraInfo serverStatusInfo = param as ServerExtraInfo; if (VersionUtils.IsPresentation) { SetScreenMode(serverStatusInfo.ScreenType); } } else { UpdateDisconnectUI(); if (MessageBox.Show(I18n.GetString("AppMessageDisconnectedFromPC"), I18n.GetString("AppMessageConfirm"), MessageBoxButton.OKCancel) == MessageBoxResult.OK) { NavigationService.Navigate(ResourceUri.ServerListPageUri); } } }); })); //쓰레드 대기 if (!connCheckDone.WaitOne(10000)) { //Deployment.Current.Dispatcher.BeginInvoke(() => // { // MessageBox.Show("타임아웃 발생"); // }); } } else { checkTime = 10000; //체크 간격을 10초로 늘림 } } //위치가 위로가면 블록킹 걸리는 경우가 있는것 같다. Thread.Sleep(checkTime); //배터리는 대략 1 ~ 2분에 한번 체크 if (batterySwitch == 20) { #if !WP7 DeviceInfo.Battery = Windows.Phone.Devices.Power.Battery.GetDefault().RemainingChargePercent; #endif batterySwitch = 1; } else { batterySwitch++; } } }