networkstream

Long Running Blocking Methods. Difference between Blocking, Sleeping, Begin/End and Async

蓝咒 提交于 2020-01-13 05:06:31
问题 This question is not about designs or patterns and which to use. The heart of this question is about what is happening regarding threads and blocking. This example is to apply to any blocking method that is designed to perform the same action continuously. In this case it is a blocking read or write on a networkstream. Is there any appreciable difference behind the scenes as to threading and performance between the methods? My assumption is that each of the methods below creates a thread or

C# and NetworkStream, sending is ok but receiving is not working

試著忘記壹切 提交于 2020-01-07 08:31:46
问题 here is the source code, I can't understand what happens. When I receive data from server then writes back to the NetworkStream then it works but when I try to send first before reading from the server it does not work : void BtnConnectClick(object sender, EventArgs e) { TcpClient clientSocket = null; NetworkStream networkStream = null; try{ clientSocket = new TcpClient(); clientSocket.SendTimeout = 5000; clientSocket.ReceiveTimeout = 5000; clientSocket.Connect("192.168.0.13",7777);

NetworkStream ReadAsync and WriteAsync hang infinitelly when using CancellationTokenSource - Deadlock Caused by Task.Result (or Task.Wait)

烂漫一生 提交于 2020-01-06 08:07:29
问题 After reading pretty much every question on Stack Overflow and Microsoft's documentation about NetworkStream, I dont understand what is wrong with my code. The problem I see is that my method GetDataAsync() hangs very often. I call this method from Init Method like so: public MyView(string id) { InitializeComponent(); MyViewModel myViewModel = session.Resolve<MyViewModel>(); //Autofac myiewModel.Init(id); BindingContext = myViewModel; } Above, my View does its initialization, then resolves

Sound keeps playing after external swf was unloaded

假装没事ソ 提交于 2020-01-04 04:43:26
问题 I have a flash application, some kind of a play-list that loads external SWF video player (I don't have code access to that external file), so users can watch the video or skip to another one. When user switches to another video new SWF file is being loaded. The problem : If user didn't finish watching the video and skips to the next then I unload previous SWF file ( unloadAndStop() ) and load a new one. And because the previous SWF was playing it is not actually unloaded, it is still playing

TcpClient disconnect during async read

本秂侑毒 提交于 2020-01-01 14:39:58
问题 I have a few questions about finishing a tcp connection. A client connects to my server using Tcp, after accepting the client with listener.BeginAcceptTcpClient(ConnectionEstabilishedCallback, null); , I start to read with networkStream.BeginRead(....) . What happens when the client disconnects while I wait for a message? (e.g. it loses power, internet, etc) How do I know when it happens? If after a successful read, I do some stuff, and then call networkStream.Close(); client.Close(); What

TcpClient disconnect during async read

纵饮孤独 提交于 2020-01-01 14:39:12
问题 I have a few questions about finishing a tcp connection. A client connects to my server using Tcp, after accepting the client with listener.BeginAcceptTcpClient(ConnectionEstabilishedCallback, null); , I start to read with networkStream.BeginRead(....) . What happens when the client disconnects while I wait for a message? (e.g. it loses power, internet, etc) How do I know when it happens? If after a successful read, I do some stuff, and then call networkStream.Close(); client.Close(); What

Why would BufferedStream.Write throw “This stream does not support seek operations”?

人走茶凉 提交于 2020-01-01 09:10:52
问题 This one puzzles me. I get an error about seek when I'm not even calling it? I have code that looks something like this: // send 42 uint value = 42; byte[] msg = BitConverter.GetBytes(value); stream.Write(msg, 0, sizeof(uint)); and I get this exception: System.NotSupportedException was unhandled Message="This stream does not support seek operations." Source="System" StackTrace: at System.Net.Sockets.NetworkStream.Seek(Int64 offset, SeekOrigin origin) at System.IO.BufferedStream.FlushRead() at

How I can play streaming audio over Ethernet in Qt?

梦想的初衷 提交于 2019-12-30 01:19:10
问题 My goal is to transmit *.wav file over LAN network without delay or with minimal one. Also we read a file on a server machine by parts, 320 bytes both. After this we send packets by UDP and write receiving in jitter-buffer. The size of the jitter-buffer is 10. What delays should I set on timers for clear sound? Here is the sender: void MainWindow::on_start_tx_triggered() { timer1 = new QTimer (this); udpSocketout = new QUdpSocket(this); qDebug()<<"Start"; for (int i = 0; i < playlist.size();

Reading on a NetworkStream = 100% CPU usage

霸气de小男生 提交于 2019-12-29 07:55:31
问题 I am reading from a NetworkStream that is in a while loop. The issue is I am seeing 100% CPU usage. Is there any way to stop this from happening? Here is what I have so far: while (client != null && client.Connected) { NetworkStream stream = client.GetStream(); data = null; try { // Check if we are still connected. if (client.Client.Poll(0, SelectMode.SelectRead)) { byte[] checkConn = new byte[1]; if (client.Client.Receive(checkConn, SocketFlags.Peek) == 0) { throw new IOException(); } } if

How to moq a NetworkStream in a unit test?

人盡茶涼 提交于 2019-12-29 05:07:24
问题 I'm using Moq & NUnit as a unit test framework. I've written a method that is given a NetworkStream object as a parameter: public static void ReadDataIntoBuffer(NetworkStream networkStream, Queue dataBuffer) { if ((networkStream != null) && (dataBuffer != null)) { while (networkStream.DataAvailable) { byte[] tempBuffer = new byte[512]; // read the data from the network stream into the temporary buffer Int32 numberOfBytesRead = networkStream.Read(tempBuffer, 0, 512); // move all data into the