Hello Kris, > now and then the WSocket->>>OnDataAvailable does not get triggered
This is because UDP is not reliable. If packet is received between the time you close the socket and set it to listen, then it is trow away. But wy ? Just connect, send, and that's all. If someone sends back the OnDataAvailable will fire. Dont call Close. > WSocket->>MultiCast=true; Wy is this nececary ? --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Sunday, April 2, 2006, 11:46, Kris Schoofs wrote: > Thanks Angus. Suggesting to use UDP made it suddenly a lot more > comprehensible... > I've played around with it and I've noticed that all UPnP devices on the > network repond with an unicast message sent to my IP on the same port that I > previously had used to multicast the UDP containing the discovery request. > ** My outgoing UDP Packet : > Internet Protocol, Src: 10.0.0.39 (10.0.0.39), Dst: 239.255.255.250 > (239.255.255.250) > User Datagram Protocol, Src Port: 1059 (1059), Dst Port: 1900 (1900) > ** An incoming UDP Packet in response to my discovery request : > Internet Protocol, Src: 10.0.0.138 (10.0.0.138), Dst: 10.0.0.39 (10.0.0.39) > User Datagram Protocol, Src Port: 1900 (1900), Dst Port: 1059 (1059) > So, what I now do is multicast the UDP Packet, remember the port that was > used for sending (WSocket->LocalPort), close the socket. And immediately > re-open it but this time for listening on that same port... > // SEND WSocket->>Proto="udp"; WSocket->>Port=1900; WSocket->>Addr ="239.255.255.250"; WSocket->>MultiCast=true; WSocket->>Connect(); > String MyPort=WSocket->LocalPort; WSocket->>SendStr(SSDP_Message); WSocket->>Close(); > // LISTEN WSocket->>Addr="0.0.0.0"; WSocket->>Port=MyPort; WSocket->>MultiCast=false; WSocket->>OnDataAvailable=WSocketDataAvailable; WSocket->>Listen(); > This seems to work fine most of the time. However, every now and then the WSocket->>OnDataAvailable does not get triggered. Any ideas what is causing > this ? Is it OK to close the socket after sending and then immediately open > it again for listening on that same port ? > Thanks. > Kris > //-------------------------------------------------------------------------- > - > void __fastcall TMainForm::WSocketDataAvailable(TObject *Sender, WORD Error) > { > char Buffer[1024]; > int Len; > TSockAddrIn Src; > int SrcLen; > SrcLen = sizeof(Src); Len = WSocket->>ReceiveFrom(Buffer, sizeof(Buffer), Src, SrcLen); if (Len >>= 0) { > Buffer[Len] = 0; > DataAvailableLabel->Caption = > IntToStr(atoi(DataAvailableLabel->Caption.c_str()) + 1) + > ": " + Buffer; > } > } > //-------------------------------------------------------------------------- > - > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Angus Robertson - Magenta Systems Ltd > Sent: vrijdag 31 maart 2006 1:54 > To: twsocket@elists.org > Subject: Re: [twsocket] THttpCli and UPnP devices >> I'm having a first look at discovering UPnP devices and I was >> wondering if THttpCli can be used for this purpose ? >> >> Communicating with UPnP devices uses HTTP over UDP (HTTPMU and HTTPU). >> In order to discover devices you send(post) a HTTP request using the >> multicast address 239.255.255.250 on port 1900. All devices should >> then respond to this request. > It's not really HTTP as such, it's just a UDP broadcast that should cause > one UDP packet to be returned by each device, each packet containing HTTP > formatted data. Sounds like a one hour project. > Forget THttpCli, it uses TCP/IP with connections, totally different to > UDP. > Angus > -- > To unsubscribe or change your settings for TWSocket mailing list please goto > http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be