|
-
Feb 16th, 2008, 08:03 PM
#1
[RESOLVED] Multiple UDP listeners
I'm working on a project that will have numerous components. I intend to have multiple components running on each of several computers. Originally, I thought that I could broadcast UDP signals from any one computer and have them picked up by multiple components on either the same computer or other computers in a LAN.
Under VB6, it was possible to establish a connection between two programs running on the same system. This doesn't appear to be possible with VB.NET. It appears to be impossible to have two sockets using UDP and listening on the same port. When I attempt to set up two sockets and bind them to the same port, I get the message "Only one usage of each socket address (protocol/network address/port) is normally permitted."
Technically, I could get around this by having only a single listener on each computer delegating messages to each process, but it isn't quite as nice a solution, especially since I want to bring modules on one after another. Ideally, each module would not need to even know whether or not it was sharing a system with other modules, and UDP appeared to be the way to do this.
Any suggestions?
My usual boring signature: Nothing
 
-
Feb 16th, 2008, 09:01 PM
#2
Re: Multiple UDP listeners
To enable your socket to be bound to an address thats already in use, I think you'd need to set the ReuseAddress socket option to true.
vb Code:
mySocket.SetSocketOption(Net.Sockets.SocketOptionLevel.Socket, Net.Sockets.SocketOptionName.ReuseAddress, True)
-
Feb 16th, 2008, 09:04 PM
#3
Re: Multiple UDP listeners
Let me test that. Wait one.
My usual boring signature: Nothing
 
-
Feb 16th, 2008, 09:27 PM
#4
Re: Multiple UDP listeners
At least half a solution. No errors anymore, but not picking anything up, either. The design is that one module sends a small array to port 11011, while another module is listening to port 11011. The sending process keeps on sending, once every 2s waiting for the listener to receive. The sender is sending to the broadcast IP, while the listener is bound to IP.Any. This was working between two systems, and I don't get any errors on a single system, but nothing is being received, or else it would be sending something back, and it's not.
My usual boring signature: Nothing
 
-
Feb 16th, 2008, 10:12 PM
#5
Re: Multiple UDP listeners
After further testing, I found that this line is causing a problem:
locUDPOut.SendTo(bytearray,length,broadcast,broadcastIP)
I altered the arguments to simplify them, but they are correct. The first argument is a byte array, the second is the length, the third is a socketflag setting of broadcast, and the last is a IPEndPoint set to IPAddress.Broadcast.
The error I am getting is 10045, which is "The attempted operation is not supported for the type of object referenced."
Therefore, the reason I am not getting anything in is because I am not sending anything out. locUDPOut was orignally a UDPClient object and was only used for sending data. Since you don't get to SetSocketOptions on a UDPClient, and I had no reason not to be using the underlying Socket directly, so I switched. In fact, in another app, I need to use the socket, because I understand the UDPListener class is buggy, so for bi-directional stuff on a socket I should just use the socket class. If I'm going to use it in one case, might as well use it in all cases.
At first I was using Send, but that only works on a connected socket. Apparently it worked for UDPClient, since I had that working between two computers, and now that I have changed the UDPClient to just a socket, Send eventually gives me an error (but takes some time doing so). Because of this, it looked like I should be using SendTo instead of Send, but I'm getting the exact same error with SendTo as I did with Send.
Back to the internet....and here I am.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|