Hello all,
I'm writing a small program that communicates with MIDI over LAN devices.  I can send UDP packets no problems...  But it's the receiving part that is not working.  The packets are "connection-less" and are broadcasted for everyone to "capture" or receive if you will...
Here's my code, looks legit:
CreateNetworkServer(0, 21929, #PB_Network_UDP)
...
  If NetworkServerEvent() = #PB_NetworkEvent_Data    
    ReceiveNetworkData(EventClient(), *DataBuffer, 2048)
    Debug "Received UDP"
  EndIf
...
CloseNetworkServer(0)
My "NetworkServerEvent()" never gets triggered by my multicast UDP packets.  Now, how does one "listen" to the network and read those precious packets?  Thanks in advance,
Marc Girard aka Khorus
			
			
									
									
						Receiving UDP multicast packets?
Re: Receiving UDP multicast packets?
Are you sure that your pc is getting the data passed any firewalls?
I just ran your code; slightly modified, and it worked as expected...

			
			
									
									
						I just ran your code; slightly modified, and it worked as expected...
Code: Select all
If InitNetwork() And CreateNetworkServer(0, 21929, #PB_Network_UDP)
  *DataBuffer = AllocateMemory(2048)
  Repeat 
    If NetworkServerEvent() = #PB_NetworkEvent_Data 
      ReceiveNetworkData(EventClient(), *DataBuffer, 2048)
      Debug "Received UDP: "+PeekS(*DataBuffer,30)
    EndIf
    Delay(10)
  ForEver
EndIf
CloseNetworkServer(0)
Re: Receiving UDP multicast packets?
Thanks Jassing for checking my code!   I slept on it yesterday and woke up this morning thinking that the problem might be in the UDP Multicasts.   They are *NOT* addressed to my IP.  The MIDI device sends it on "225.0.0.37" (some sort of a broadcast address I believe).  Wireshark receives them OK, I completely disabled my firewall.
The funny part is that the other way around works well, here's what I used:
OpenNetworkConnection("225.0.0.37", 21928, #PB_Network_UDP) and the usual SendNetworkString...
Looks like PureBasic needs to be triggered by the machine's local IP address (or 127.0.0.1).
Let me know if you have any ideas! Thanks again!
Marc Girard aka Khorus
			
			
									
									
						The funny part is that the other way around works well, here's what I used:
OpenNetworkConnection("225.0.0.37", 21928, #PB_Network_UDP) and the usual SendNetworkString...
Looks like PureBasic needs to be triggered by the machine's local IP address (or 127.0.0.1).
Let me know if you have any ideas! Thanks again!
Marc Girard aka Khorus
Re: Receiving UDP multicast packets?
I've written something like that (listening to Multicast stuff received over an address that is not the address of my NW-Adapter) via C++ a few days ago. But I'm not sure if you can do this with PB-Network functions. Anyway you can use sockets in PB as well 
 ...otherwise I'm not sure how you could add something like "setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr));" or "setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));" to your socket created in background via CreateNetworkServer. And otherwise if you miss that why should your server ever listen on an address that does not really belong to him (even 0.0.0.0 is "too less" here). So I would recommend use some socket_(), setsockopt_(), bind_(), setsockopt_(), recvfrom_() instead the CreateNetworkServer - and probably take a look here: http://tldp.org/HOWTO/Multicast-HOWTO-6.html
Greetings,
auser
			
			
									
									
						Greetings,
auser
Re: Receiving UDP multicast packets?
I wasn't able to receive Multicast Sockets using Purebasic in C# i used an option like  to make this work.
Anyone out there had made this work for purebasic?
			
			
									
									
						Code: Select all
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));Anyone out there had made this work for purebasic?
Re: Receiving UDP multicast packets?
Hi,
with pure PureBasic it is not possible.
I did it with window socket stuff.
I wrote a small program to receive the MicroChip network broadcasts.
Maybe I'll have already written about this. I'll check.
Found it:
http://www.purebasic.fr/english/viewtop ... 18#p451018
Bernd
			
			
									
									
						with pure PureBasic it is not possible.
I did it with window socket stuff.
I wrote a small program to receive the MicroChip network broadcasts.
Maybe I'll have already written about this. I'll check.
Found it:
http://www.purebasic.fr/english/viewtop ... 18#p451018
Bernd




