|
From: Andy W. S. <an...@cn...> - 2009-11-12 21:04:46
|
The IP header has two fields for source and destination port. In most cases you don't specify a source port, just a destination. In this case the operating system automatically assigns one to your connection, typically with a "high number" (> 15000). When you traverse a NAT device, the source port gets changed and the NAT router maintains a table of which address to forward packets based on their source port. When your server receives a packet, it simply swaps the source and destination ports to make a packet that will travel in the other direction. This packet will arrive at the client regardless of how many NAT devices are in between. This works for both UDP and TCP. Services like Skype (and also Ross Bencinas' oscgroups server) use a special technique called NAT hole punching that uses an intermediary to relay what the NAT holes are between to clients. Unless you have an ultra-restrictive firewall this will pretty much always work. When you use the function recv() you can't make a reply packet because the source port isn't provided. The function recvfrom() is identical but also fills a structure (passed by reference) with extra information about the source of the packet, including the address and source port. Meanwhile the client will need to find out what port the OS assigned to them, and start listening for a reply packet on that port. Many OSC libraries have "forgotten" about bidirectional UDP, but this is actually the basis of how the internet works (DNS would never work without it, for example). Anyways I don't know how its done in liblo, but hopefully this helps.... Andy. On Nov 12, 2009, at 12:07 PM, IOhannes m zmoelnig wrote: > hi all. > > sorry if this comes through twice; i keep using the wrong address for > sending emails... > > for my midi-over-osc project i have to establish a bidirectional > communication over WAN. > > i wanted to use liblo for this, but have trouble finding the relevant > information in the API-documentation. > > so my question is: > - how do tell my server to send back a message to a connected client? > it would be sufficient to broadcast to all connected clients (only one > is supposed to be connected) > > i understand the problem when using UDP, but really i am using TCP/IP. > the client will be behind a natted firewall, without the possibility > to > open any ports. > > there seems to be a way to get the source of an incoming message with > "lo_message_get_source()", but how on earth do i get lo_messages out > of > the server? --- Andy W. Schmeder andy [at] cnmat.berkeley.edu Programmer/Analyst II Research Group Center for New Music and Audio Technologies University of California at Berkeley http://cnmat.berkeley.edu |