networkstream

[.NET] BeginReceive / BeginRead timeouts

I'm using a NetworkStream & TcpClient to asynchronously receive data using BeginRead. I need to apply a time-out to this operation, such that after a specified amount of time the read will be aborted. As far as I'm able to tell, this isn't supported on NetworkStream or TcpClient - there is a ReceiveTimeout property, but this appears to...

IRC using NetworkStream - buffer fills and line gets chomped

var buffer = new byte[short.MaxValue]; var splitString = new string[] {"\r\n"}; while (_tcpClient.Connected) { if (!_networkStream.CanRead || !_networkStream.DataAvailable) continue; var bytesRead = _networkStream.Read(buffer, 0, buffer.Length); var stringBuffer = Encoding.ASCII.GetString(buffer, 0, bytesRead); var message...

protobuf-csharp-port

Hi, I'm using Jon Skeet's (excellent) port of Google's Protocol Buffers to C#/.Net. For practice, I have written a dummy Instant Messenger app that sends some messages down a socket. I have a message definition as follows:- message InstantMessage { required string Message = 1; required int64 TimeStampTicks = 2; } When the send...

Using a NetworkStream to transfer a file

I am having trouble transferring a file to a client from a server program. A few problems I would like to address. First is that I make the byte array 6000 bytes big and its always that size. Is there a way to maintain the correct file size? Also with the way the code is now, the program hangs. It works when I take it out of the while lo...

Transfering a File with a NetworkStream then rebuilding the file fails.

I am trying to send a file over a NetworkStream and rebuild it on the client side. I can get the data over correctly (i think) but when I use either a BinaryWriter or a FileStream object to recreate the file, the file is cut off in the beginning at the same point no matter what methodology I use. private void ReadandSaveFileFromServe...

Transfering items over NetworkStream causes some data to get clobbered

I am sending a filename(string), filesize(int), and the file(byte[]). What is happening is that in certain cases, depending on how quickly the data gets processed on the server side, the NetworkStream has read the data that I dont need yet. Example: I do a .Read to get the filename, I will get the data for filename,filesize and the fi...

Reading on a NetworkStream = 100% CPU usage

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; ...

Larger File Sizes are being incorrectly transfered with a NetworkStream

I am transferring a file over a NetworkStream and it seems that when the file goes over about 5-10k, the file starts to miss out on data and/or have huge whitespace gaps. Here is what I have: private string ReadandSaveFileFromServer(TcpClient clientATF, NetworkStream currentStream, string locationToSave) { int fileSize = 0; st...

Sound keeps playing after external swf was unloaded

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 th...

Is it possible to write/read directly TCP Streams in ASP.NET?

I'd like to write and read TCP Streams directly without any modifications by ASP or IIS. Is this possible? Edit: Goal is to provide communication between a program and a server. Data exchange between them is less then 25 bytes per connection (in default case). So Headers will cause more traffic then the real data. I need to use ASP.Net ...

How to tell in protobuf-net how many bytes were read from a NetworkStream on a call to DeserializeWithLengthPrefix

Is there a way to do this? I would like to know how many bytes were read from a NetworkStream when I call DeserializeWithLengthPrefix. Since NetworkStream does not support the Position property I cannot see a simple way to do this. Can this be done in a reasonably efficient way? I need to know this for profiling purposes, and it would be...