473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

URGENT - InvalidOperationException on UDP ReceiveFrom call

I have an application that we are porting from Unmanaged C++ to VB.NET
that involves sockets. There are two pieces to the code. One piece is
a one to one TCP call to a server which is working fine. The second
piece receives streaming data from the server on a regular basis via
UDP. My problem is that I can not make the ReceiveFrom call work.
This code is multithreaded and I don't know if that has any bearing on
it or not.

First off, I make a call to the function "OpenStreaming" which does the
following:
m_StreamSocket = New Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)

Dim sockaddr_in As New
System.Net.SocketAddress(AddressFamily.InterNetwor k)
Dim sep As New System.Net.IPEndPoint(System.Net.IPAddress.Any, nPort)
globalPort = nPort
m_StreamSocket.Bind(sep.Create(sockaddr_in))

Dim stws As New StreamThreadWithState(Me)
m_hStreamThread = New System.Threading.Thread(AddressOf
stws.StreamThread)
m_hStreamThread.Start()

"StreamThread" runs with the following code:

While (1)

Dim nResult As System.Int32

' Call StreamHandler(), the main worker function of this thread
nResult = pThis.StreamHandler

' Check for error. Timeout errors are okay in this instance.
If (((O22SIOMM.SIOMM_OK <> nResult) And (O22SIOMM.SIOMM_TIME_OUT <>
nResult))) Then
Exit While
End If

' Check flag to see if we should keep looping
If pThis.m_bListenToStreaming = False Then
' Stop looping
nResult = O22SIOMM.SIOMM_OK
Exit While
End If

' Check the timeouts of all stream items

pThis.CheckStreamTimeouts()

pThis.m_hStreamThread.Sleep(1)
End While
The "StreamHandler" code is as follows:

Dim ecode As Int32
Dim nResult As System.Int32
Dim bCriticalSectionFlag As Boolean = True

Try
If (m_StreamSocket Is Nothing) Then
StreamHandler = SIOMM_ERROR_NOT_CONNECTED
Exit Function
End If
Catch e As SocketException
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
e.Message, e.ErrorCode)
StreamHandler = SIOMM_TIME_OUT
Exit Function
Catch e As ObjectDisposedException
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
e.Message)
StreamHandler = SIOMM_TIME_OUT
Exit Function
Catch e As Exception
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
e.Message)
StreamHandler = SIOMM_TIME_OUT
Exit Function
End Try
' Creates an IpEndPoint to capture the identity of the sending host.
Dim sender As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Dim SourceAddr As System.Net.EndPoint = CType(sender,
System.Net.EndPoint)
Try
Dim lep As System.Net.EndPoint
Dim lipep As System.Net.IPEndPoint
Dim lip As System.Net.IPAddress
lip = New
System.Net.IPAddress(System.Net.IPAddress.Parse(Sy stem.Net.Dns.GetHostByName(System.Net.Dns.GetHostN ame).AddressList(0).ToString()).Address)
lipep = New System.Net.IPEndPoint(lip, globalPort)
lep = lipep
' lep = New System.Net.IPEndPoint(lip, globalPort)
' lep = New System.Net.IPEndPoint(System.Net.IPAddress.Any,
globalPort)
' m_StreamSocket.Bind(lep)
Dim testbytes() As Byte
ReDim testbytes(100)
Dim idx
For idx = LBound(testbytes) To UBound(testbytes)
testbytes(idx) = New Byte
testbytes(idx) = 0
Next idx
'm_StreamSocket.SendTo(testbytes, SourceAddr)
'Result = m_StreamSocket.ReceiveFrom(m_pbyLastStreamBlock,
m_nStreamLength, SocketFlags.None, SourceAddr)

'NOTE: I have already called BIND from OpenStreaming function
'HERE IS WHERE I BLOW UP
nResult = m_StreamSocket.ReceiveFrom(m_pbyLastStreamBlock, 660,
SocketFlags.None, SourceAddr)
Catch e As SocketException
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
"m_StreamSocket.Bind : " & e.Message, e.ErrorCode)
nResult = e.ErrorCode
StreamHandler = SIOMM_ERROR
Exit Function
Catch e As ObjectDisposedException
StreamHandler = SIOMM_ERROR
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
"m_StreamSocket.Bind : " & e.Message)
Exit Function
Catch e As Exception
m_O22UTILS.writeOptoErrorToLog(Me.GetType.Name & ".StreamHandler",
"m_StreamSocket.Bind : " & e.Message)
StreamHandler = SIOMM_ERROR

Exit Function
End Try


Next I make a call to "StartStreamListening" which does: (I don't think
this is important because I am not even getting data from the server
yet because of the receiveFrom failure)

m_StreamCriticalSection.WaitOne()
Checks a list of classes for data. Each class is supposed to have data
or they will not be in the list
m_StreamCriticalSection.ReleaseMutex()

I have to ship this product by Friday 5/6/2005 and I am panicking
because this function is the only item left to port before thorough
testing can begin.

Please , Please, Please can someone help.

Thanks,
Mike Dixon

Nov 22 '05 #1
0 1234

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Rice | last post by:
Hello, Im trying to get the following working but it doesn't seem to receive anything. I have got the UdpClient class to receive data but unreliably and was told to use the Socket class...
0
by: Frustrated | last post by:
I have an application that we are porting from Unmanaged C++ to VB.NET that involves sockets. There are two pieces to the code. One piece is a one to one TCP call to a server which is working...
3
by: Fred Palmer | last post by:
I am trying to get reponses from multiple devices on my network by sending the following message via UDP: // Create the message Byte bytesSent = new Byte {0x00, 0x00, 0x00, 0xF6}; Socket s =...
1
by: Nuno Magalhaes | last post by:
Does the function below returns an UDP packet, for example, from the local machine? Why does it give me an error: "The best overloaded method match for ReceiveFrom... has some invalid arguments"....
0
by: Nuno Magalhaes | last post by:
The MSDN says that I have to bind the socket on a local address to use ReceiveFrom function. How can I bind the socket on a multicast address in order to get the multicast data. Say that I want to...
0
by: Nuno Magalhaes | last post by:
The MSDN says that I have to bind the socket on a local address to use ReceiveFrom function. How can I bind the socket on a multicast address in order to get the multicast data. Say that I want to...
0
by: alok sengar | last post by:
hi, I have already tried this URL's code "http://www.java2s.com/Code/CSharp/Network/SimpleSNMP.htm" but I am getting error when i am creating a UDP type Socket and recieving packet from this...
1
by: alok sengar | last post by:
hi, I have already tried this URL's code "http://www.java2s.com/Code/CSharp/Network/SimpleSNMP.htm" but I am getting error when i am creating a UDP type Socket and recieving packet from this...
5
by: igotyourdotnet | last post by:
I'm creating a web service this is going to return an arraylist of items. When I try and run it Im' getting the following error message: System.InvalidOperationException: There was an error...
0
by: Johan | last post by:
Why is the parameter remoteEP of the function Socket.ReceiveFrom() a ref parameter and not an out parameter? http://msdn2.microsoft.com/en-us/library/wdfskwcy.aspx public int ReceiveFrom (...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.