private void StartReadingData() #endif { Task.Factory.StartNew(() => { try { #if (PORTABLE) socket.ConnectAsync(_ipAddress, _port).Wait(); #else socket.Connect(iPEndPoint); #endif #if (PORTABLE) ManualResetEvent ev = new ManualResetEvent(true); socket.MessageReceived += (s, e) => { OnReceivedData?.Invoke(e.ByteData); }; ev.WaitOne(); #else while (!IsDisposed) { byte[] bytes = new byte[BufferSize]; int readCount = socket.Receive(bytes); OnReceivedData?.Invoke(bytes.ToList().GetRange(0, readCount).ToArray()); } #endif } catch (Exception ex) { AutoLogger.LogError(ex, "UdpConnectorBase StartReadingData"); } }); }
private async Task ReceiveLoop() { Debug.Log("ReceiveLoop Start"); uint readPacketSize; CSteamID clientSteamID; try { byte[] receiveBuffer; while (Connected) { while (Receive(out readPacketSize, out clientSteamID, out receiveBuffer)) { if (readPacketSize == 0) { continue; } if (clientSteamID != hostSteamID) { Debug.LogError("Received a message from an unknown"); continue; } // we received some data, raise event OnReceivedData?.Invoke(receiveBuffer); } //not got a message - wait a bit more await Task.Delay(TimeSpan.FromSeconds(secondsBetweenPolls)); } } catch (ObjectDisposedException) { } Debug.Log("ReceiveLoop Stop"); }
public void HandleMessages() { NetIncomingMessage message; while ((message = m_Server.ReadMessage()) != null) { switch (message.MessageType) { case NetIncomingMessageType.ConnectionApproval: try { var packet = Packet.Read(message.Data); ApproveConnection(message.SenderConnection); OnConnectionApproved?.Invoke(new LidgrenMessage(message)); } catch (Exception e) { DenyConnection(message.SenderConnection); OnConnectionDenied?.Invoke(new LidgrenMessage(message)); } break; case NetIncomingMessageType.StatusChanged: switch (message.SenderConnection.Status) { case NetConnectionStatus.Connected: OnConnected?.Invoke(new LidgrenMessage(message)); break; case NetConnectionStatus.Disconnected: OnDisconnecting?.Invoke(new LidgrenMessage(message)); //not firing from lidgren OnDisconnected?.Invoke(new LidgrenMessage(message)); break; } break; case NetIncomingMessageType.Data: TriggerCallback(new LidgrenConnection(message.SenderConnection), message.Data); OnReceivedData?.Invoke(new LidgrenMessage(message)); break; case NetIncomingMessageType.DebugMessage: // handle debug messages // (only received when compiled in DEBUG mode) Console.WriteLine("DEBUG: " + message.ReadString()); break; case NetIncomingMessageType.WarningMessage: Console.WriteLine("WARNING: " + message.ReadString()); break; /* .. */ default: Console.WriteLine("unhandled message with type: " + message.MessageType); break; } } }
public ReadViewModel() { ImageTapCommand = new Command(async() => { try { if (_isTapped) { return; } _isTapped = true; if (Device.RuntimePlatform != Device.iOS) { MessagingCenter.Send <App, List <string> >((App)Xamarin.Forms.Application.Current, "Tag", new List <string> { "Test" }); } else { DependencyService.Get <INfc>().StartSession(); } _isTapped = false; } catch (Exception ex) { _isTapped = false; await Application.Current.MainPage.DisplayAlert(AppResources.Attenzione, ex.Message, AppResources.Ok); } }); PopupCommand = new Command(async() => { // If there is a popup, I close it if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Count > 0) { await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopAllAsync(); } await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(new ResultPopupPage(_arg)); }); OnAppearingCommand = new Command(() => { MessagingCenter.Subscribe <App, List <string> >(this, "Tag", (sender, arg) => { TagId = arg[0]; // Pos 0 = TagID _arg = arg; DateTime dateTime = DateTime.Now; ReceivedAt = dateTime.ToLongDateString() + "\n" + dateTime.ToLongTimeString(); OnReceivedData?.Invoke(); //Now run the Action which, if it is not null, your ContentPage should have set to do the scrolling }); }); OnDisappearingCommand = new Command(() => { MessagingCenter.Unsubscribe <App, List <string> >(this, "Tag"); }); }
protected override void OnReceiveData(byte[] data, CSteamID clientSteamID, int channel) { if (clientSteamID != hostSteamID) { Debug.LogError("Received a message from an unknown"); return; } OnReceivedData.Invoke(data, channel); }
protected override void OnReceiveData(byte[] data, ProductUserId clientUserId, int channel) { if (clientUserId != hostProductId) { Debug.LogError("Received a message from an unknown"); return; } OnReceivedData.Invoke(data, channel); }
private void AllDown(CoordinationStatus status) { // 此处没有取消和超时状态,直接完成 if (status == CoordinationStatus.AllDone) { Interlocked.Exchange(ref ConnectStatus, 0); LogNet?.WriteDebug("All bytes read complete."); OnReceivedData?.Invoke(BytesResult.ToArray()); } }
protected override void OnReceiveData(byte[] data, CSteamID clientSteamID, int channel) { if (steamToMirrorIds.TryGetValue(clientSteamID, out int connectionId)) { OnReceivedData.Invoke(connectionId, data, channel); } else { CloseP2PSessionWithUser(clientSteamID); Debug.LogError("Data received from steam client thats not known " + clientSteamID); OnReceivedError.Invoke(-1, new Exception("ERROR Unknown SteamID")); } }
protected override void OnReceiveData(byte[] data, ProductUserId clientUserId, int channel) { if (epicToMirrorIds.TryGetValue(clientUserId, out int connectionId)) { OnReceivedData.Invoke(connectionId, data, channel); } else { CloseP2PSessionWithUser(clientUserId); string productId; clientUserId.ToString(out productId); Debug.LogError("Data received from epic client thats not known " + productId); OnReceivedError.Invoke(-1, new Exception("ERROR Unknown product ID")); } }
protected override void OnReceiveData(byte[] data, SteamId clientSteamID, int channel) { if (steamToMirrorIds.Contains(clientSteamID)) { int connectionId = steamToMirrorIds[clientSteamID]; OnReceivedData?.Invoke(connectionId, data, channel); } else { CloseP2PSessionWithUser(clientSteamID); Debug.LogError("Data received from steam client thats not known " + clientSteamID); OnReceivedError?.Invoke(-1, new Exception("ERROR Unknown SteamID")); } }
public async void Listen() { while (true) { try { TcpClient client = await _serverSocket.AcceptTcpClientAsync(); _timer.Stop(); _timer.Start(); string ip = client.Client.RemoteEndPoint.AddressFamily.ToString(); IPEndPoint remoteIpEndPoint = client.Client.RemoteEndPoint as IPEndPoint; IPEndPoint localIpEndPoint = client.Client.LocalEndPoint as IPEndPoint; NetworkStream stream = client.GetStream(); byte[] bufferSend = StreamHelper.GetBytes(stream); byte[] bufferReply = OnReceivedData?.Invoke(remoteIpEndPoint?.Address.ToString(), bufferSend); if (bufferReply != null) { StreamHelper.SendBytes(stream, bufferReply); } stream.Close(); } catch (SocketException socketException) { Console.WriteLine(socketException); return; } catch (InvalidOperationException invalidOperationException) { Console.WriteLine(invalidOperationException); return; } catch (Exception e) { Console.WriteLine(e); return; } } }
//start to reading data from server void StartReadingData() { Task.Factory.StartNew(() => { try { socket.Connect(iPEndPoint); while (!IsDisposed) { byte[] bytes = new byte[BufferSize]; var readCount = socket.Receive(bytes); OnReceivedData?.Invoke(bytes.ToList().GetRange(0, readCount).ToArray()); } } catch (Exception ex) { AutoLogger.LogError(ex, "UdpConnectorBase StartReadingData"); } }); }
private async Task ReceiveLoop() { Debug.Log("ReceiveLoop Start"); uint readPacketSize; SteamId clientSteamID; try { byte[] receiveBuffer; while (!Offline) { for (int i = 0; i < channels.Length; i++) { while (Receive(out readPacketSize, out clientSteamID, out receiveBuffer, i)) { if (readPacketSize == 0) { continue; } try { int connectionId = steamConnectionMap.fromSteamID[clientSteamID].connectionID; // we received some data, raise event OnReceivedData?.Invoke(connectionId, receiveBuffer, i); } catch (KeyNotFoundException) { CloseP2PSessionWithUser(clientSteamID); //we have no idea who this connection is Debug.LogError("Data received from steam client thats not known " + clientSteamID); OnReceivedError?.Invoke(-1, new Exception("ERROR Unknown SteamID")); } } } //not got a message - wait a bit more await Task.Delay(TimeSpan.FromSeconds(secondsBetweenPolls)); } } catch (ObjectDisposedException) { } Debug.Log("ReceiveLoop Stop"); }
/// <summary> /// Es llamado desde el servidor al cliente, cuando el cliente encuentra su señal /// Informa a todos los componentes suscritos al Callback con la data del Servidor encontrado /// </summary> /// <param name="fromAddress"></param> /// <param name="data"></param> public override void OnReceivedBroadcast(string fromAddress, string data) { base.OnReceivedBroadcast(fromAddress, data); OnReceivedDataCallback.Invoke(data, fromAddress.Split(':')[3]); }