networkstream

How to properly handle incoming protobuf message with a NetworkStream?

∥☆過路亽.° 提交于 2019-12-11 04:24:17
问题 Using TCPClient's NetworkStream and protobuf-net I send and receive protobuf messages via TCP. Receiving is done with the following method that runs in an own thread: private void HandleClientComm() { using (NetworkStream stream = m_Stream) { object o; while (true) { if (stream.CanRead && stream.DataAvailable) { o = null; if (Serializer.NonGeneric.TryDeserializeWithLengthPrefix(stream, PrefixStyle.Base128, Utilities.CommunicationHelper.resolver, out o)) { if (o != null) { //Do something with

How to ensure that all data are read from a NetworkStream

给你一囗甜甜゛ 提交于 2019-12-11 01:12:28
问题 Is sure that all data are read from a NetworkStream when DataAvailable is false? Or does the sender of the data have to send the length of the data first. And I have to read until I have read the number of bytes specified by the sender? Sampel: private Byte[] ReadStream(NetworkStream ns) { var bl = new List<Byte>(); var receivedBytes = new Byte[128]; while (ns.DataAvailable) { var bytesRead = ns.Read(receivedBytes, 0, receivedBytes.Length); if (bytesRead == receivedBytes.Length) bl.AddRange

networkstream “cannot access a disposed object” when using newly created networkstream

别来无恙 提交于 2019-12-10 22:14:38
问题 I have a few different methods which connect to a remote host, send a message, get a reply, and use the information. this has worked fine until i use two methods in the same instance of my connection class. in the example where i'm getting the error, i run the following method; public string sendRequestAccountID(string siteID) { //build message String response = String.Empty; TcpClient client = new TcpClient(); client.Connect(detailsHere); NetworkStream stream = client.GetStream();

Reading information from a port waits even though data available

[亡魂溺海] 提交于 2019-12-10 11:35:36
问题 I am having a problem sending information down a socket and receiving a response. I have a demo program which is performing correctly so I know it is not an issue with the client on the other end. The requestData is sent and the client acts correctly and responds, but my code never exits the loop in read response. Could the client be responding before I am listening? How can I make sure I never miss an incoming message? networkStream = tcpClient.GetStream(); StreamWriter clientStreamWriter =

.NET TcpClient/NetworkStream implementation that supports async operations and respects timeouts

孤者浪人 提交于 2019-12-10 05:16:25
问题 Based on the number of questions, forum posts, etc, it appears that the TcpClient/NetworkStream implementation in the BCL lacks decent support for cancelling IO operations. With the addition of Async methods in .NET 4.5, this lack of cancellation (or decent timeout support) makes things even more frustrating since it becomes even more complicated (nigh on impossible) to cancel a task that refuses to monitor its CancellationToken while performing IO. I have seen many implementations that spin

NetworkStream, is there something similar to DataReceived for a SerialPort? (C#)

為{幸葍}努か 提交于 2019-12-08 22:06:01
问题 Ok, so I'm a little confused as to why I can't find this anywhere, or if it doesn't exist then why have Microsoft not implemented it? So here's my scenario, I have a NetworkStream, which has a lovely little boolean called DataAvailable, and what I need is an event, that jumps out and says "Hey, there's data available for you!" (because I'm lazy and I'd rather be told that there's data available than to keep asking "Alright, is there any data available?" over and over again until I get the

ACM Stream Convert exception displaying AcmNotPossible

有些话、适合烂在心里 提交于 2019-12-08 09:45:18
问题 When decompressing frames of Mp3 from Server the above mentioned exception occurs while the Mp3 have been played for 10 to 15 sec.My application is a Client/Server application.I m sending the Mp3 Frames by composing Mp3 Packets and serializing it over Network Stream.I m using NAudio Open Source API for Compressing and Decompressing Frames and Playing the Mp3.I get the following exception with Stack Trace. NAudio.MmException.Try(MmResult result, String function) at NAudio.Wave.Compression

Reading from a network stream: packet fragmentation

穿精又带淫゛_ 提交于 2019-12-08 07:37:36
问题 I got a server that is managing two clients through NetworkStream.Read . Application protocol is: ClientMessage [128 Bytes] → Response from Server [128 Bytes] Now at server-side: Is it possible, that MyTcpClient.GetStream().Read() returns only < 128 Bytes, although all messages from client-side are exactly 128 bytes long? I guess that such a client message is short enough to fit into one packet on the tcp/ip layer - but could there be some kind of fragmentation or random although? Is

Communicate between two systems using only MAC address

安稳与你 提交于 2019-12-08 03:43:30
问题 I want to know how to communicate between two systems using only MAC address using C program (without using IP address). I think this is raw ethernet communication. My requirement is to send data from client to server only by using the MAC address. May be this can be done by creating our own raw ethernet frame. Please help me regarding this. If anybody has written code in C, please share. This link may help you, http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html 回答1: The libpcap

C# NetworkStream.DataAvailable seems to be unreliable

馋奶兔 提交于 2019-12-08 02:01:13
问题 I have an app that uses a TCP socket to exchange byte arrays which in most cases contain JSON string data. What I'm experiencing is that, for larger messages and less than ideal network conditions, use of NetworkStream.DataAvailable does NOT seem to be a reliable way to detect an end of message. It seems that in some cases DataAvailable is set to false even when only part of the message has been transmitted by peer (which is using TcpClient.GetStream().Write(data, 0, data.Length ). This