public Boolean PressedVirtualButton(ButtonTypes button) { Boolean isRequested = false; if (ConnectionInfo.CurrentServer.IsConnected) { byte[] packet = null; SocketAsyncEventArgs socketArg = new SocketAsyncEventArgs(); PacketInfo packetInfo = new PacketInfo(); packetInfo.AccessCode = ConnectionInfo.CurrentServer.AccessCode; packetInfo.PacketType = PacketTypes.VirtualButton; packetInfo.ButtonType = button; packetInfo.DeviceType = DeviceType; packet = PacketUtils.MakeClientPacket(packetInfo); socketArg.SetBuffer(packet, 0, packet.Length); ConnectionInfo.TcpSocket.NoDelay = true; isRequested = ConnectionInfo.TcpSocket.SendAsync(socketArg); //데이터 사용량 누적 if (socketArg.BytesTransferred > 0) { AppLoader.CellularDataUtil.SumUsageCellularData(socketArg.BytesTransferred); } } return(isRequested); }
public Boolean KeyRelease(KeyboardInfo keyboardInfo) { Boolean isRequested = false; if (ConnectionInfo != null && ConnectionInfo.CurrentServer.IsConnected) { byte[] packet = null; SocketAsyncEventArgs socketArg = new SocketAsyncEventArgs(); PacketInfo packetInfo = new PacketInfo(); packetInfo.AccessCode = ConnectionInfo.CurrentServer.AccessCode; packetInfo.PacketType = PacketTypes.Keyboard; packetInfo.DeviceType = DeviceTypes.Keyboard; packetInfo.KeyboardInfo = keyboardInfo; packet = PacketUtils.MakeClientPacket(packetInfo); socketArg.SetBuffer(packet, 0, packet.Length); socketArg.RemoteEndPoint = ConnectionInfo.CurrentServer.UdpIPEndPoint; UdpSocket udpSocket = new UdpSocket(); isRequested = udpSocket.SendToAsync(socketArg); //데이터 사용량 누적 if (socketArg.BytesTransferred > 0) { AppLoader.CellularDataUtil.SumUsageCellularData(socketArg.BytesTransferred); } } return(isRequested); }
private void findServer() { //UDP소켓 생성 int port = Convert.ToInt32(portTxtBox.Text.Trim()); currentHostname = hostTxtBox.Text.Trim(); if (!NetworkUtils.IsNetworkAvailable) { NetworkUtils.ShowWiFiSettingPage(I18n.GetString("AppMessageRequiredDataNetwork"), I18n.GetString("AppMessageNotification")); return; } ////서버 리스트 비우기 serverInfoList.Clear(); PacketInfo packetInfo = new PacketInfo(); packetInfo.PacketType = PacketTypes.FindServer; packetInfo.DeviceType = DeviceTypes.None; byte[] buffer = PacketUtils.MakeClientPacket(packetInfo); DnsEndPoint dnsEp = new DnsEndPoint(currentHostname, port); udpSocket = new UdpSocket(); SocketAsyncEventArgs udpSockArgs = new SocketAsyncEventArgs(); udpSockArgs.RemoteEndPoint = dnsEp; udpSockArgs.SetBuffer(buffer, 0, buffer.Length); udpSockArgs.Completed += udpSockArgs_Completed; //PC검색 패킷 발송 udpSocket.SendToAsync(udpSockArgs); }
public void SaveLastConnectedServer(DeviceTypes deviceType) { SettingManager.Set(SettingManager.KEY_SERVER_NAME, ConnectionInfo.CurrentServer.ServerName); SettingManager.Set(SettingManager.KEY_SERVER_IP, ConnectionInfo.CurrentServer.ServerIP); SettingManager.Set(SettingManager.KEY_SERVER_TCP_PORT, ConnectionInfo.CurrentServer.TcpPort); SettingManager.Set(SettingManager.KEY_SERVER_UDP_PORT, ConnectionInfo.CurrentServer.UdpPort); SettingManager.Set(SettingManager.KEY_SERVER_ACCESS_CODE, ConnectionInfo.CurrentServer.AccessCode); SettingManager.Update(); packetInfo.Clear(); packetInfo.PacketType = PacketTypes.AutoConnect; packetInfo.DeviceType = deviceType; packetInfo.AccessCode = ConnectionInfo.CurrentServer.AccessCode; SocketAsyncEventArgs tcpSocketArgs = new SocketAsyncEventArgs(); tcpSocketArgs.RemoteEndPoint = ConnectionInfo.CurrentServer.TcpIPEndPoint; //기존 패킷에 패킷타입만 바꿔서, 패킷 새로 생성 byte[] packet = PacketUtils.MakeClientPacket(packetInfo); tcpSocketArgs.SetBuffer(packet, 0, packet.Length); ConnectionInfo.TcpSocket.SendAsync(tcpSocketArgs); }
public Boolean MoveTouch(TouchInfo[] touchInfos) { Boolean isSuccess = false; if (ConnectionInfo.CurrentServer.IsConnected) { byte[] packet = null; if (pointingUdpSocket == null) { pointingUdpSocket = new UdpSocket(); } SocketAsyncEventArgs udpSocketArg = new SocketAsyncEventArgs(); movePacket.Clear(); movePacket.DeviceType = DeviceType; movePacket.ButtonType = SettingInfo.UseExtendButton ? ButtonTypes.Navigation : ButtonTypes.None; movePacket.AccessCode = ConnectionInfo.CurrentServer.AccessCode; movePacket.PacketType = PacketTypes.Coordinates; movePacket.TouchInfos = touchInfos; packet = PacketUtils.MakeClientPacket(movePacket); //패킷 전송 udpSocketArg.RemoteEndPoint = ConnectionInfo.CurrentServer.UdpIPEndPoint; udpSocketArg.SetBuffer(packet, 0, packet.Length); pointingUdpSocket.SendToAsync(udpSocketArg); //데이터 사용량 누적 if (udpSocketArg.BytesTransferred > 0) { AppLoader.CellularDataUtil.SumUsageCellularData(udpSocketArg.BytesTransferred); } } return(isSuccess); }
public Object ConnectServer(DeviceTypes deviceType, CallbackHandler connectResult) { if (!NetworkUtils.IsNetworkAvailable) { NetworkUtils.ShowWiFiSettingPage(I18n.GetString("AppMessageRequiredDataNetwork"), I18n.GetString("AppMessageNotification")); return(SocketError.NotConnected); } Object result = SocketError.TimedOut; ConnectionInfo.TcpSocket = new TcpSocket(); ConnectionInfo.TcpSocket.NoDelay = true; packetInfo.Clear(); packetInfo.PacketType = PacketTypes.Authentication; packetInfo.DeviceType = deviceType; packetInfo.AccessCode = ConnectionInfo.CurrentServer.AccessCode; SocketAsyncEventArgs tcpSocketArgs = new SocketAsyncEventArgs(); tcpSocketArgs.RemoteEndPoint = ConnectionInfo.CurrentServer.TcpIPEndPoint; tcpSocketArgs.UserToken = new UserToken(packetInfo, connectResult); tcpSocketArgs.Completed += new EventHandler <SocketAsyncEventArgs>((object s, SocketAsyncEventArgs e) => { result = e.SocketError; // Signal that the request is complete, unblocking the UI thread _clientDone.Set(); if (e.SocketError == SocketError.Success) { //데이터 사용량 누적 if (e.BytesTransferred > 0) { AppLoader.CellularDataUtil.SumUsageCellularData(tcpSocketArgs.BytesTransferred); } UserToken userToken = null; switch (e.LastOperation) { case SocketAsyncOperation.Connect: if (e.ConnectSocket != null) { if (e.ConnectSocket.Connected) { byte[] packet = PacketUtils.MakeClientPacket(e.UserToken); e.SetBuffer(packet, 0, packet.Length); e.ConnectSocket.SendAsync(e); } } else { userToken = e.UserToken as UserToken; if (userToken.callback != null) { ConnectionInfo.CurrentServer.IsConnected = false; ((CallbackHandler)userToken.callback)(null); } } break; case SocketAsyncOperation.Send: userToken = e.UserToken as UserToken; if (userToken.PacketInfo.PacketType == PacketTypes.Authentication) { byte[] packet = new byte[1024]; e.SetBuffer(packet, 0, packet.Length); e.ConnectSocket.ReceiveAsync(e); } break; case SocketAsyncOperation.Receive: userToken = e.UserToken as UserToken; ServerExtraInfo serverExtraInfo = (ServerExtraInfo)PacketUtils.ResolveServerPacket(PacketTypes.Authentication, e); ConnectionInfo.CurrentServer.IsConnected = serverExtraInfo != null; //결과 UI반영 if (userToken.callback != null) { ((CallbackHandler)userToken.callback)(serverExtraInfo); } //System.Diagnostics.Debug.WriteLine("접속 소켓 실행 결과 : " + result.ToString()); break; } } }); _clientDone.Reset(); ConnectionInfo.TcpSocket.ConnectAsync(tcpSocketArgs); _clientDone.WaitOne(5000); //에러가 타임 아웃인 경우 강제적으로 콜백을 호출한다. if ((SocketError)result == SocketError.TimedOut) { connectResult(SocketError.TimedOut); } return(result); }
public Object CheckConnection(SettingInfo settingInfo, CallbackHandler checkConnectionResult) { if (!NetworkUtils.IsNetworkAvailable) { NetworkUtils.ShowWiFiSettingPage(I18n.GetString("AppMessageRequiredDataNetwork"), I18n.GetString("AppMessageNotification")); return(SocketError.NotConnected); } Object result = SocketError.TimedOut; packetInfo.Clear(); packetInfo.PacketType = PacketTypes.CheckConnection; packetInfo.DeviceType = settingInfo.DeviceType; packetInfo.AccessCode = ConnectionInfo.CurrentServer.AccessCode; SocketAsyncEventArgs tcpSocketArgs = new SocketAsyncEventArgs(); tcpSocketArgs.RemoteEndPoint = ConnectionInfo.CurrentServer.TcpIPEndPoint; tcpSocketArgs.UserToken = new UserToken(packetInfo, checkConnectionResult); byte[] packet = PacketUtils.MakeClientPacket(packetInfo); tcpSocketArgs.SetBuffer(packet, 0, packet.Length); tcpSocketArgs.Completed += new EventHandler <SocketAsyncEventArgs>((object s, SocketAsyncEventArgs e) => { result = e.SocketError; if (e.SocketError == SocketError.Success) { //데이터 사용량 누적 if (e.BytesTransferred > 0) { AppLoader.CellularDataUtil.SumUsageCellularData(tcpSocketArgs.BytesTransferred); } UserToken userToken = null; switch (e.LastOperation) { case SocketAsyncOperation.Send: userToken = e.UserToken as UserToken; //if (e.Buffer.Length == 0) //{ // System.Diagnostics.Debug.WriteLine("뭥미"); //} packet = new byte[1024]; e.SetBuffer(packet, 0, packet.Length); ConnectionInfo.TcpSocket.ReceiveAsync(e); break; case SocketAsyncOperation.Receive: userToken = e.UserToken as UserToken; ServerExtraInfo serverStatusInfo = (ServerExtraInfo)PacketUtils.ResolveServerPacket(PacketTypes.CheckConnection, e); if (serverStatusInfo == null) { if (ConnectionInfo.TcpSocket.Connected) { //끊김 확인용 e.SetBuffer(0, 0); ConnectionInfo.TcpSocket.SendAsync(e); } else { result = SocketError.ConnectionAborted; _clientDone.Set(); } } else { _clientDone.Set(); //결과 UI반영 if (userToken.callback != null) { ((CallbackHandler)userToken.callback)(serverStatusInfo); } } break; } } else { _clientDone.Set(); System.Diagnostics.Debug.WriteLine("끊김 재확인 => 소켓 에러 : " + result); } }); if (IsConnected) { _clientDone.Reset(); ConnectionInfo.TcpSocket.NoDelay = true; ConnectionInfo.TcpSocket.SendAsync(tcpSocketArgs); _clientDone.WaitOne(3000); } if ((SocketError)result != SocketError.Success) { System.Diagnostics.Debug.WriteLine("커넥션 체크 중 소켓 에러 : " + (SocketError)result); if (ConnectionInfo.CurrentServer.IsConnected) { DisconnectServer(checkConnectionResult); } } return(result); }