networkstream

Get Data from Bluetooth device in C#

牧云@^-^@ 提交于 2019-11-29 10:28:13
问题 I'm trying to get data from a medical BT device that I already have pairing code and communication protocol. Looking for some code I've got this code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using InTheHand.Net.Sockets; using InTheHand.Net; using InTheHand.Net.Bluetooth; using InTheHand.Windows.Forms; using System.Net.Sockets; using System.Diagnostics; using System.Threading; namespace dConsoleApp { static class Program { // My BT USB adapter

How to moq a NetworkStream in a unit test?

倖福魔咒の 提交于 2019-11-29 01:27:29
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 main buffer for (Int32 i = 0; i < numberOfBytesRead; i++) { dataBuffer.Enqueue(tempBuffer[i]); } } }

How I can play streaming audio over Ethernet in Qt?

懵懂的女人 提交于 2019-11-28 21:53:57
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(); ++i) { inputFile.setFileName(playlist.at(i)); qDebug()<<inputFile.fileName(); if (!inputFile.open

Read bytes from NetworkStream (Hangs)

十年热恋 提交于 2019-11-28 11:28:56
问题 I'm trying to learn the basics of networking and I've built an echo server from this tutorial. I checked the server with telnet and it works perfect. Now when I'm using some of the many client samples on the Internet: // Create a TcpClient. // Note, for this client to work you need to have a TcpServer // connected to the same address as specified by the server, port // combination. TcpClient client = new TcpClient(server, port); // Translate the passed message into ASCII and store it as a

TCP client\\server - client doesn't always read

邮差的信 提交于 2019-11-28 10:36:09
Client Code: TcpClient client = new TcpClient(); NetworkStream ns; private void Form1_Load(object sender, EventArgs e) { try { client.Connect("127.0.0.1", 560); ns = client.GetStream(); byte[] buffer = ReadFully(ns, client.Available); //working with the buffer... } catch { //displaying error... } } public static byte[] ReadFully(NetworkStream stream , int initialLength) { // If we've been passed an unhelpful initial length, just // use 32K. if (initialLength < 1) { initialLength = 32768; } byte[] buffer = new byte[initialLength]; long read = 0; int chunk; while ((chunk = stream.Read(buffer,

C# read all bytes

可紊 提交于 2019-11-28 09:55:35
问题 I am trying to write a simple client/server application in C#. The following is an example server reply sent to my client: reply {20}<entry name="test"/> where {20} indicates number of chars that full reply contains. In the code I wrote below how can I use this number to loop and read ALL chars? TcpClient tcpClient = new TcpClient(host, port); NetworkStream networkStream = tcpClient.GetStream(); ... // Server Reply if (networkStream.CanRead) { // Buffer to store the response bytes. byte[]

Difference between NetworkStream.Read() and NetworkStream.BeginRead()?

梦想与她 提交于 2019-11-28 06:37:32
I need to read from NetworkStream which would send data randomly and the size of data packets also keep varying. I am implementing a multi-threaded application where each thread would have its own stream to read from. If there is no data on the stream, the application should keep waiting for the data to arrive. However, if the server is done sending data and has terminated the session, then it should exit out. Initially I had utilised the Read method to obtain the data from the stream, but it used to block the thread and kept waiting until data appeared on the stream. The documentation on MSDN

Get Length of Data Available in NetworkStream

前提是你 提交于 2019-11-28 01:59:47
I would like to be able to get the length of the data available from a TCP network stream in C# to set the size of the buffer before reading from the network stream. There is a NetworkStream.Length property but it isn't implemented yet, and I don't want to allocate an enormous size for the buffer as it would take up too much space. The only way I though of doing it would be to precede the data transfer with another telling the size, but this seems a little messy. What would be the best way for me to go about doing this. Tim S. When accessing Stream s , you usually read and write data in small

How to get all data from NetworkStream

倾然丶 夕夏残阳落幕 提交于 2019-11-27 13:44:09
I am trying to read all data present in the buffer of the Machine connected through TCP/IP but i don't know why i am not getting all data ,some data is getting Missed. Here is the code that i am using .. using (NetworkStream stream = client.GetStream()) { byte[] data = new byte[1024]; int numBytesRead = stream.Read(data, 0, data.Length); if (numBytesRead > 0) { string str= Encoding.ASCII.GetString(data, 0, numBytesRead); } } Please tell me what i am missing to get all the data from the machine. Thanks in advance.. The problem with your code is that you will not get all the data if the data

TcpClient.GetStream().DataAvailable returns false, but stream has more data

流过昼夜 提交于 2019-11-27 04:28:57
问题 So, it would seem that a blocking Read() can return before it is done receiving all of the data being sent to it. In turn we wrap the Read() with a loop that is controlled by the DataAvailable value from the stream in question. The problem is that you can receive more data while in this while loop, but there is no behind the scenes processing going on to let the system know this. Most of the solutions I have found to this on the net have not been applicable in one way or another to me. What I