private async void RecvData(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args) { StreamReader reader = new StreamReader(args.GetDataStream().AsStreamForRead()); string data = reader.ReadToEnd(); NodeBroadcastInfo nodeInfo = ParseData(ref data); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() => { nodeBroadcastInfoViewModel.updateNode(nodeInfo); })); if (NodeTable.ContainsKey(nodeInfo.Name)) { MaoNode node = NodeTable[nodeInfo.Name]; if (node.IP != nodeInfo.IP) { node.updateIP(nodeInfo.IP); } node.seeAgain(); } else { NodeTable.Add(nodeInfo.Name, new MaoNode(nodeInfo.Name, nodeInfo.IP)); } }
async void OnMessage(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { using (var stream = args.GetDataStream().AsStreamForRead()) { await stream.ReadAsync(buffer, 0, MAX_BUFFER_SIZE); Vector3 cameraPosition = new Vector3( BitConverter.ToSingle(buffer, 0), BitConverter.ToSingle(buffer, 4), BitConverter.ToSingle(buffer, 8)); Quaternion cameraRotation = new Quaternion( BitConverter.ToSingle(buffer, 12), BitConverter.ToSingle(buffer, 16), BitConverter.ToSingle(buffer, 20), BitConverter.ToSingle(buffer, 24)); string address = args.RemoteAddress.ToString(); object[] values = new object[] { cameraPosition, cameraRotation }; lock (devices.SyncRoot) { devices[address] = values; } } }
private async void SocketOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var result = args.GetDataStream(); var resultStream = result.AsStreamForRead(1024); try { byte[] buffer = new byte[5]; byte[] message = IPMessage(); await resultStream.ReadAsync(buffer, 0, 5); for (int i = 0; i <= 5; i++) //compare arrays { if (buffer[i] != message[i]) { if (buffer[0] == 1 && OnClientFound != null) { await SendMessage(message, args.RemoteAddress.ToString(), args.RemotePort); OnClientFound(buffer.Skip(1).ToArray()); break; } } } } catch { //TODO: Error handler } }
private async void SocketOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { // Creates a reader for the incoming message var resultStream = args.GetDataStream().AsStreamForRead(1024); using (var reader = new StreamReader(resultStream)) { // Get the message received string message = await reader.ReadToEndAsync(); // Cheks if the message is a response from a server if (message.StartsWith("WSRESPONSE", StringComparison.CurrentCultureIgnoreCase)) { // Spected format: WSRESPONSE;<ID>;<HTTP ADDRESS> var splitedMessage = message.Split(';'); if (splitedMessage.Length == 3) { var id = splitedMessage[1]; var url = splitedMessage[2]; _endPoints.Add(new WSEndpoint() { ID = id, URL = url }); } } } }
private async void SocketOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var result = args.GetDataStream(); var resultStream = result.AsStreamForRead(1024); if (!IsListening) { return; } using (var reader = new StreamReader(resultStream)) { var text = await reader.ReadToEndAsync(); Debug.LogFormat("Service discovered {0}", text); if (text.Contains(serviceName)) { string[] split = text.Split(':'); Debug.LogFormat("Broadcasting discovered service {0}", text); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { Debug.LogFormat("Broadcasting {0} {1}", args.RemoteAddress.DisplayName, split[1]); OnServiceDiscovered(text, args.RemoteAddress.DisplayName, int.Parse(split[1])); }); } } }
/// <summary> /// Delegate for when a datagram is received /// </summary> private async void LeapDataReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { try { Stream inStream = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(inStream); string data = await reader.ReadLineAsync(); LeapFrameData frameData = JsonUtility.FromJson <LeapFrameData>(data); // Temp workaround because JsonUtility creates objects even if you have an empty JSON string if (!data.Contains("left_arm")) { frameData.left_arm = null; } if (!data.Contains("right_arm")) { frameData.right_arm = null; } _frameStream.OnNext(frameData); } catch (Exception e) { Debug.LogErrorFormat("Exception when receiving Leap data: {0}", e.Message); } }
private async void ReceiveUDP_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream inStream = args.GetDataStream().AsStreamForRead(); String ipFrom = args.RemoteAddress.ToString(); if (ipFrom.Equals(app.localIP)) { } else { app.partIP = ipFrom; } //data got StreamReader reader = new StreamReader(inStream); string msg = await reader.ReadLineAsync(); if (ipFrom.Equals(app.partIP)) { app.publicKey = msg; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (() => { keyBox.Text = sessionKey; LocalIPBox.Text = app.localIP; PartIPBox.Text = app.partIP; PartkeyBox.Text = app.publicKey; })); } }
private async void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream inputStream = args.GetDataStream().AsStreamForRead(); StreamReader streamReader = new StreamReader(inputStream); string recievedMessage = await streamReader.ReadLineAsync(); print("received: " + recievedMessage); }
private async void SocketMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream streamIn = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(streamIn); string message = await reader.ReadLineAsync(); ParseMessage(message); }
async void OnMessage(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { using (var stream = args.GetDataStream().AsStreamForRead()) { await stream.ReadAsync(buffer, 0, MAX_BUFFER_SIZE); lock (lockObject_) { osc_.FeedData(buffer); } } }
// receive message private async void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { //Read the message that was received from the UDP echo client. Stream streamIn = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(streamIn); message = await reader.ReadLineAsync(); msgReceived = true; }
async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { StreamReader reader = new StreamReader(args.GetDataStream().AsStreamForRead()); string data = await reader.ReadLineAsync(); if (UdpNetworkListenEvent != null) { UdpNetworkListenEvent(data, args.RemoteAddress.DisplayName); } }
async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream streamIn = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(streamIn); string data = await reader.ReadLineAsync(); if (UdpNetworkListenEvent != null) { UdpNetworkListenEvent(data); } }
private async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { String msg = await readMessage(args.GetDataStream()); this.OutputString("Received from" + args.RemoteAddress.RawName + ": " + msg); } ); }
private async void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { byte[] data = new byte[BUFFER_SIZE]; IBuffer buffer = data.AsBuffer(); IInputStream input = args.GetDataStream(); await input.ReadAsync(buffer, BUFFER_SIZE, InputStreamOptions.Partial); MessageReceived?.Invoke(this, data.Take((int)buffer.Length).ToArray()); _sw = _sw ?? Stopwatch.StartNew(); _sw.Restart(); }
private void UdpMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var action = MessageRecieved; if (action != null) { using (var reader = new StreamReader(args.GetDataStream().AsStreamForRead())) { action(reader.ReadToEnd()); } } }
private void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { using (var s = args.GetDataStream().AsStreamForRead()) using (var ms = new MemoryStream()) { s.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); var json = Encoding.UTF8.GetString(ms.ToArray()); Debug.Log($"Received Json: {json}"); this.CommandQueue.Enqueue(JsonUtility.FromJson <Command>(json)); } }
private async void SocketOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var result = args.GetDataStream(); var resultStream = result.AsStreamForRead(1024); using (var reader = new StreamReader(resultStream)) { var text = await reader.ReadToEndAsync(); //Debug.Log("MESSAGE: " + text); } }
/// <summary> /// Adds the manager to the list of Managers, when a UDP advertisement message is received.. /// </summary> private async void AdvertisementMessageReceivedFromManagerAsync(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { // Read the advertisement message. using (var reader = new StreamReader(args.GetDataStream().AsStreamForRead())) { string message = await reader.ReadLineAsync(); // Add the manager to the list of Managers. base.AddManager(new UdpManagerInformation { Host = args.RemoteAddress }, message); } }
/// <summary> /// データ受信時の処理を行います /// </summary> async void OnMessage(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { using (var stream = args.GetDataStream().AsStreamForRead()) { byte[] buffer = new byte[MAX_BUFFER_SIZE]; await stream.ReadAsync(buffer, 0, MAX_BUFFER_SIZE); lock (lockObject) { // データ受信処理 } } }
async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { StreamReader reader = new StreamReader(args.GetDataStream().AsStreamForRead()); string ms = await reader.ReadLineAsync(); Debug.Log("Message received: " + ms); if (ms != null && ms.Trim() != "") { VeriController.flag = 1; VeriController.ms = ms; } }
private async void SocketMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { try { Stream streamIn = args.GetDataStream().AsStreamForRead(); MemoryStream ms = ToMemoryStream(streamIn); OnMessageReceivedEvent(new Message(ms.ToArray())); } catch (Exception ex) { Debug.LogError(ex.ToString()); } }
async void OnMessage(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { using (var stream = args.GetDataStream().AsStreamForRead()) { var size = await stream.ReadAsync(buffer, 0, BufferSize); lock (lockObject_) { var data = new byte[size]; Array.Copy(buffer, data, size); messageQueue_.Enqueue(data); } } }
private async void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream inputStream = args.GetDataStream().AsStreamForRead(); StreamReader streamReader = new StreamReader(inputStream); string recievedMessage = await streamReader.ReadLineAsync(); //todo do THings with message print("received: " + recievedMessage); //var values = recievedMessage.Split(' '); //float temp1 = float.Parse(values[0]); //float temp2 = float.Parse(values[1]); //print(temp1); //print(temp2); }
//async private async void ServerSocket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Debug.Log("MessageReceivedEvent"); if (ReceivingStatus != AWAITING_IMAGE) { return; // dont do anything if not ready to receive } await System.Threading.Tasks.Task.Run(() => { Stream streamIn = args.GetDataStream().AsStreamForRead(); byte[] data = ToMemoryStream(streamIn).ToArray(); // enqueue all, continually stack // used for managing events, creates a group of actions ExecuteOnMainThread.Enqueue(() => ProcessPacket(data)); }); }
async void MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream streamIn = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(streamIn); message = await reader.ReadLineAsync(); // log Debug.Log("Neobox found at address: " + args.RemoteAddress); // printer Debug.Log("Hololens local address : " + args.LocalAddress); // hololens // save printer address address = args.RemoteAddress.ToString(); address = "192.168.1.107"; }
/// <summary> /// When a new message is received, the participant is added to the list of Participants. /// </summary> private async void MessageToConnectReceivedFromParticipantAsync(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var participant = new UdpParticipantInformation { Host = args.RemoteAddress }; // Read the subscriber's message. using (var reader = new StreamReader(args.GetDataStream().AsStreamForRead())) { string message = await reader.ReadLineAsync(); // Add the participant. base.AddParticipant(participant, message); } }
async void socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { IInputStream result = args.GetDataStream(); var resultStream = result.AsStreamForRead(1024); string text = ""; using (var reader = new StreamReader(resultStream)) { text = await reader.ReadToEndAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { txtServerResponse.Text = text; }); }
private void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var stream = args.GetDataStream().AsStreamForRead(); int count = stream.Read(_buffer, 0, _buffer.Length); if (count > 0) { if (_bufferEndPoint == null || !_bufferEndPoint.HostName.IsEqual(args.RemoteAddress) || !_bufferEndPoint.PortStr.Equals(args.RemotePort)) { _bufferEndPoint = new NetEndPoint(args.RemoteAddress, args.RemotePort); } _onMessageReceived(_buffer, count, 0, _bufferEndPoint); } }
private async void Listener_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { try { Stream streamIn = args.GetDataStream().AsStreamForRead(); StreamReader reader = new StreamReader(streamIn); string message = await reader.ReadToEndAsync(); lock (_receiveQueueLock) { _receiveQueue.Enqueue(message); } } catch (Exception e) { Debug.Log("DATA LISTENER EXCEPTION: " + e.ToString()); Debug.Log(SocketError.GetStatus(e.HResult).ToString()); return; } }
private void OnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var result = args.GetDataStream().ReadAsync(_buffer, _buffer.Capacity, InputStreamOptions.None).AsTask().Result; int length = (int)result.Length; if (length <= 0) return; if (_bufferEndPoint == null || !_bufferEndPoint.HostName.IsEqual(args.RemoteAddress) || !_bufferEndPoint.PortStr.Equals(args.RemotePort)) { _bufferEndPoint = new NetEndPoint(args.RemoteAddress, args.RemotePort); } _onMessageReceived(_byteBuffer, length, 0, _bufferEndPoint); }