It is currently Thu Jun 20, 2013 11:05 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Receiving UDP multicast packets?
PostPosted: Wed Apr 04, 2012 5:51 am 
Offline
User
User

Joined: Sat Nov 13, 2010 11:22 pm
Posts: 23
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


Top
 Profile  
 
 Post subject: Re: Receiving UDP multicast packets?
PostPosted: Wed Apr 04, 2012 7:36 am 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 1008
Location: Anderson Island, WA
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...

Code:
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)

Image


Top
 Profile  
 
 Post subject: Re: Receiving UDP multicast packets?
PostPosted: Wed Apr 04, 2012 2:40 pm 
Offline
User
User

Joined: Sat Nov 13, 2010 11:22 pm
Posts: 23
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


Top
 Profile  
 
 Post subject: Re: Receiving UDP multicast packets?
PostPosted: Wed Apr 11, 2012 1:15 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 06, 2006 6:59 am
Posts: 151
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Justin and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye