bigfoot3d
Well-known member
When I run my code with no limitation on the network side, either by running from a localhost or running on a Local Area Network Connection, i get no problems whatsoever and it all just works.
However when I go ahead and put limitations on the speed either by running it across the internet or by setting a limitation on my network speed using a bandwidth manager, I then run into System.OutofMemoryExceptions.
I was wondering if there is anyway around this. I am thinking it has something to do with the buffer on the receive side that I am not clearing out correctly because the limitation is usually on the upload side. This is for the server part of my application. So the download speed is at least 200k and the upload is only 45 - 70k depending on the ISP's mood that day.
I figured that the receiving side is getting backed up by the sending side because of the limited upload speed. So the received side's buffer is just running out of memory because of the queuing its doing waiting to send to the upload side.
I am using this to transfer screenshots, so I am not really worried about losing screenshots that are taken while the uploading stream is in use.
I was thinking about having the receiving computer send a message to the sending computer through the server to send the next image once it has completely received the current image off of the stream, that way only one image would be transferred at a time. However that just seems as a workaround to me, and not a true solution.
Here is server side code for receiving the images:
and here is the server side code with some additional tweaking to try to get rid of the extra buffered memory, but no luck.
Any ideas or suggestions to over come this the proper way? I mean i can do a workaround like i mentioned above, but I would rather have something properly done rather than a workaround.
Thanks in advance for any comments or suggestions!
However when I go ahead and put limitations on the speed either by running it across the internet or by setting a limitation on my network speed using a bandwidth manager, I then run into System.OutofMemoryExceptions.
I was wondering if there is anyway around this. I am thinking it has something to do with the buffer on the receive side that I am not clearing out correctly because the limitation is usually on the upload side. This is for the server part of my application. So the download speed is at least 200k and the upload is only 45 - 70k depending on the ISP's mood that day.
I figured that the receiving side is getting backed up by the sending side because of the limited upload speed. So the received side's buffer is just running out of memory because of the queuing its doing waiting to send to the upload side.
I am using this to transfer screenshots, so I am not really worried about losing screenshots that are taken while the uploading stream is in use.
I was thinking about having the receiving computer send a message to the sending computer through the server to send the next image once it has completely received the current image off of the stream, that way only one image would be transferred at a time. However that just seems as a workaround to me, and not a true solution.
Here is server side code for receiving the images:
VB.NET:
Private Sub HFHClientSendScreenLink()
Try
While Connected
If ConnectedtoTech Then
Dim br As New IO.BinaryReader(HFHClientSendScreen)
ThisClientsTech.HFHTechRecScreenLink(New IO.MemoryStream(br.ReadBytes(br.ReadInt32)))
End If
End While
Catch e As Exception
If e.Message = "Unable to read beyond the end of the stream." Then ' add here
Exit Sub
ElseIf e.Message = "Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall." Then
Exit Sub
Else
MessageBox.Show("Check Me", "Check Me", MessageBoxButtons.OK)
End If
End Try
End Sub
and here is the server side code with some additional tweaking to try to get rid of the extra buffered memory, but no luck.
VB.NET:
Private Sub HFHClientSendScreenLink()
SendScreenToTech = True
While Connected
Try
If ConnectedtoTech Then
Dim br As New IO.BinaryReader(HFHClientSendScreen)
Dim ScreenMemory As New IO.MemoryStream(br.ReadBytes(br.ReadInt32))
If SendScreenToTech Then
SendScreenToTech = False
ScreenMemorytoSend = ScreenMemory
Dim SendScreenTech As New Thread(New ThreadStart(AddressOf ShipScreentoTech))
SendScreenTech.Start()
End If
ScreenMemory.Dispose()
br = Nothing
End If
Catch e As Exception
If e.Message = "Unable to read beyond the end of the stream." Then ' add here
Exit Sub
ElseIf e.Message = "Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall." Then
Exit Sub
ElseIf e.Message = "Non-negative number required." & vbNewLine & "Parameter name: count" Then
HFHClientSendScreen.Flush
ElseIf e.Message = "Unable to read data from the transport connection: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full." Then
HFHClientSendScreen.Flush()
ElseIf e.Message = "Stream was not writable." Then
Exit Sub
Else
MessageBox.Show("Check Me " + vbNewLine + vbNewLine + e.Message + vbNewLine + vbNewLine + e.StackTrace + " " + e.Source + vbNewLine + e.ToString + vbNewLine + e.ToString, "Check Me", MessageBoxButtons.OK)
End If
End Try
End While
End Sub
Any ideas or suggestions to over come this the proper way? I mean i can do a workaround like i mentioned above, but I would rather have something properly done rather than a workaround.
Thanks in advance for any comments or suggestions!