Re: [twsocket] THttpCli and UPnP devices

2006-04-09 Thread Francois PIETTE
> I tried this and this works great ! Thanks.

Would be very nice if you publish some finalized code. You can get an entry 
on the "usermade" page at ICS website.

--
[EMAIL PROTECTED]
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


Re: [twsocket] THttpCli and UPnP devices

2006-04-05 Thread Kris Schoofs
 
> With UDP, connect and listen seem to be the same thing.  So specify Addr
and Port, 
> then connect, send, and you'll get your responses in data available. 

I tried this and this works great ! Thanks.
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Angus Robertson - Magenta Systems Ltd
Sent: dinsdag 4 april 2006 22:06
To: twsocket@elists.org
Subject: Re: [twsocket] THttpCli and UPnP devices

> (2) With the code below I open port 2500 for listening, multicast a 
> packet, and then listen for 5 seconds before closing the socket.
> However, if I try to repeat this sequence a 2nd time, even though I've 
> closed the socket after listening for 5 seconds, I get following error

I've just been writing a UDP echo component, which is very similar what you
doing.  With UDP, connect and listen seem to be the same thing.  So specify
Addr and Port, then connect, send, and you'll get your responses in data
available.  

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-04 Thread Dan
- Original Message - 
From: "Kris Schoofs" <[EMAIL PROTECTED]>
To: "'ICS support mailing'" 
Sent: Tuesday, April 04, 2006 6:20 PM
Subject: Re: [twsocket] THttpCli and UPnP devices


> Hi Wilfried,
>
>> WSocket->>MultiCast=true;
>> Why is this nececary ?
> Well, discovery of UPnP devices require that you multicast an UDP packet 
> to
> 239.255.255.250:1900. All devices will then unicast a packet back to the
> sender. And since my discovery request needed to multicast I assume that I
> also needed to set WSocket->>MultiCast=true;
>
> Based on the info in your other posting I now realize that a socket can 
> send
> and receive both and so I rewrote my code accordingly. Now, I open the
> socket for listening and then use SendTo to send the packet. This seems to
> work much better now (no more packet loss).
>
> However, I still have some questions
>
> (1) Previously, when I opened the socket with ->>Connect() I got myself a
> free port number assigned in WSocket->>Port. This way I didn't have to 
> worry
> about which port I could use since I always got a free one assigned.
> However, now I open the socket with Listen(); and this requires me to 
> define
> WSocket->>Port before calling the Listen(). This makes sense because 
> usually
> you know where you want to listen. However, in my case I'm listening for
> responses that are sent back to the port I've used for sending the 
> discovery
> request. So, any port will be fine. For now, I've just put in a fixed port
> number to test my code, but I cannot always be sure if that port is
> available. So, I was wondering if it is possible to request WinSock for an
> available port that I can use (just like you get a port when using
> Connect()) ?

As an alternative to what Angus suggested, you could continue to listen but 
specify port 0.  The OS will then assign an unused port.  There is a winsock 
call you can use on the socket handle to get the port allocated but I don't 
remember it off the top of my head, and you wouldnt really need to know the 
port anyway.

Dan 

-- 
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


Re: [twsocket] THttpCli and UPnP devices

2006-04-04 Thread Angus Robertson - Magenta Systems Ltd
> (2) With the code below I open port 2500 for listening, multicast a 
> packet, and then listen for 5 seconds before closing the socket. 
> However, if I try to repeat this sequence a 2nd time, even though
> I've closed the socket after listening for 5 seconds, I get
> following error 

I've just been writing a UDP echo component, which is very similar what 
you doing.  With UDP, connect and listen seem to be the same thing.  So 
specify Addr and Port, then connect, send, and you'll get your responses 
in data available.  

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-04 Thread Kris Schoofs
Hi Wilfried,

> WSocket->>MultiCast=true;
> Why is this nececary ?
Well, discovery of UPnP devices require that you multicast an UDP packet to
239.255.255.250:1900. All devices will then unicast a packet back to the
sender. And since my discovery request needed to multicast I assume that I
also needed to set WSocket->>MultiCast=true;

Based on the info in your other posting I now realize that a socket can send
and receive both and so I rewrote my code accordingly. Now, I open the
socket for listening and then use SendTo to send the packet. This seems to
work much better now (no more packet loss). 

However, I still have some questions

(1) Previously, when I opened the socket with ->>Connect() I got myself a
free port number assigned in WSocket->>Port. This way I didn't have to worry
about which port I could use since I always got a free one assigned.
However, now I open the socket with Listen(); and this requires me to define
WSocket->>Port before calling the Listen(). This makes sense because usually
you know where you want to listen. However, in my case I'm listening for
responses that are sent back to the port I've used for sending the discovery
request. So, any port will be fine. For now, I've just put in a fixed port
number to test my code, but I cannot always be sure if that port is
available. So, I was wondering if it is possible to request WinSock for an
available port that I can use (just like you get a port when using
Connect()) ? 


(2) With the code below I open port 2500 for listening, multicast a packet,
and then listen for 5 seconds before closing the socket. However, if I try
to repeat this sequence a 2nd time, even though I've closed the socket after
listening for 5 seconds, I get following error : 'Error 10049 in function
setsockopt(IP_ADD_MEMBERSHIP) Address not available' when doing the
WSocket->>Listen(); 

Here's what I'm currently using...

// Start listening :
WSocket->>OnDataAvailable=WSocketDataAvailable;
WSocket->>Proto="udp";
WSocket->>Addr="0.0.0.0";
// For now using a fixed port value hoping it is available :
WSocket->>Port=2500;
WSocket->>Listen();

// Multicast packet so that UnP devices respond :
TSockAddr MySockAddress;
MySockAddress.sin_family=AF_INET;
MySockAddress.sin_addr.s_addr=inet_addr("239.255.255.250");
MySockAddress.sin_port=htons(atoi("1900"));
WSocket->>MultiCast=true;
WSocket->>SendTo(MySockAddress,sizeof(MySockAddress),SSDP_Message.c_str(),SS
DP_Message.Length());

CloseSocketTimer->Enabled=true;


void __fastcall TMainForm::CloseSocketTimerTimer(TObject *Sender)
{
CloseSocketTimer->>Enabled=false;
WSocket->>Close();
}

Thanks,

Kris

 

-----Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Wilfried Mestdagh
Sent: maandag 3 april 2006 8:59
To: ICS support mailing
Subject: Re: [twsocket] THttpCli and UPnP devices

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->>P

Re: [twsocket] THttpCli and UPnP devices

2006-04-03 Thread Wilfried Mestdagh
Hello Kris,

> Basically, I cannot connect to port xxx for sending when I'm already
> listening to it...

A socket can send and receive both. UDP Connect is the same as UDP
Listen. So you can not do both. The difference is the handling.

If you call connect then send, then you send to the addr:port in the
properties. LocalAddr:LocalPort are the interface the socket is bound.

If you call listen then you bind to the Addr:Port properties. If you
call Listen you have to send with SendTo.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Sunday, April 2, 2006, 22:28, Kris Schoofs wrote:

>> But that's not a problem is it?  Listen, connect, send query, wait x
> seconds for responses, stop listen, repeat... 

> I'm unable to execute the sequence you suggest.

> Listen to port xxx  : OK
> Connect to port xxx : 'winsock.bind failed, error #10048'
> So, I'm unable to send the query and that's where it ends... Nobody will
> respond.

> Basically, I cannot connect to port xxx for sending when I'm already
> listening to it...

> And my guess is that with the sequence I'm currenlty using...
> - Connect to port  : Send query
> - Close port 
> - Listen to port 
> ...There is too much delay between switching from sending to listening
> causing me to miss some of the initial UDP packets.

> When running tests I can see 3 scenarios

> Either :
> (A) I get no packets at all. 
=>> Ethereal shows for every response that was sent to me an ICMP that
> reports "destination unreachable (Port unreachable)". Apparently the socket
> is not yet listening...

> Or

> (B) I only get some of the packets. Usually the first few of the sequence
> are missing (the UPnP device I'm currently using sends back 14 packets in
> response to my discovery request). Strangely enough, Ethereal does not
> report anymore that the "destination unreachable (Port unreachable)", but
> TWSocket also does not make those initial packets available to me.

> Or

> (C) Sometimes everything works great and I get all packets sent to me (14 in
> my test case, as confirmed by Ethereal).

> I'm also wondering why sometimes OnDataAvailable is called when listening
> but Receive() reports that the received length is -1.

> SCENARIO A
> - I get nothing back
> - Ethereal shows for every response that was sent to me an ICMP that reports
> "destination unreachable (Port unreachable)".
> ==
> Send UDP : Send via port 1171
> Send UDP : DONE. Close Socket
> LISTEN UDP : listening on port 1171
> Listen UDP for 5 seconds : DONE. Close Socket
>   UDP with ReceiveLength >0 = [00]
>   UDP with ReceiveLength <1 = [00]


> SCENARIO B 
> - only 11 out of 14 packets
> - First 3 packets are missing, see scenario B
> ==
> Send UDP : Send via port 1167
> Send UDP : DONE. Close Socket
> LISTEN UDP : listening on port 1167
> UDP#01=ReceiveLen=249
> UDP#02=ReceiveLen=283
> UDP#03=ReceiveLen=249
> UDP#04=ReceiveLen=283
> UDP#05=ReceiveLen=261
> UDP#06=ReceiveLen=309
> UDP#07=ReceiveLen=296
> UDP#08=ReceiveLen=313
> UDP#09=ReceiveLen=315
> UDP#10=ReceiveLen=305
> UDP#11=ReceiveLen=305
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
>   > UDP#**=ReceiveLen=-1
> Listen UDP for 5 seconds : DONE. Close Socket
>   UDP with ReceiveLength >0 = [11]
>   UDP with ReceiveLength <1 = [10]


> SCENARIO C 
> - I get everything back nicely
> ==Send UDP : Send via port 1166
> Send UDP : DONE. Close Socket
> LISTEN UDP : listening on port 1166
> UDP#01=ReceiveLen=232
> UDP#02=ReceiveLen=243
> UDP#03=ReceiveLen=304
> UDP#04=ReceiveLen=249
> UDP#05=ReceiveLen=283
> UDP#06=ReceiveLen=249
> UDP#07=ReceiveLen=283
> UDP#08=ReceiveLen=261
> UDP#09=ReceiveLen=309
> UDP#10=ReceiveLen=296
> UDP#11=ReceiveLen=313
> UDP#12=ReceiveLen=315
> UDP#13=ReceiveLen=305
> UDP#14=ReceiveLen=305
> Listen UDP for 5 seconds : DONE. Close Socket
>   UDP with ReceiveLength >0 = [14]
>   UDP with ReceiveLength <1 = [00]

> Kris

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Angus Robertson - Magenta Systems Ltd
> Sent: zondag 2 april 2006 18:56
> To: twsocket@elists.org
> Subject: Re: [twsocket] THttpCli and UPnP devices

>> However, any subsequent attempts to use that same port for sending the
>> UDP packet fail. Only after closing the sock

Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Wilfried Mestdagh
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)
> {
> charBuffer[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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Angus Robertson - Magenta Systems Ltd
> BTW: Don't you risk a lot if you enable UpnP devices? I was told it 
> might be a security hole, so I disabled them where I could in my LAN.

Make sure such appliances have got strong admin passwords?

Discovering the devices was always possible with echo, UPnP just tells 
you a little more than they exist.  

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Angus Robertson - Magenta Systems Ltd
> Dont use connect, just use listen, but use SendTo to send the packet. 
>  This lets you specify the address.

That would make sense, with UDP connect only opens the socket, and 
listen probably does the same thing.  I've only only used UDP for 
syslog, which is one-way.  

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Dan
Dont use connect, just use listen, but use SendTo to send the packet.  This 
lets you specify the address.

Dan

- Original Message - 
From: "Kris Schoofs" <[EMAIL PROTECTED]>
To: "'ICS support mailing'" 
Sent: Sunday, April 02, 2006 10:46 AM
Subject: Re: [twsocket] THttpCli and UPnP devices


> 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)
> {
> charBuffer[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
> 

-- 
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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Kris Schoofs
> But that's not a problem is it?  Listen, connect, send query, wait x
seconds for responses, stop listen, repeat... 

I'm unable to execute the sequence you suggest.

Listen to port xxx  : OK
Connect to port xxx : 'winsock.bind failed, error #10048'
So, I'm unable to send the query and that's where it ends... Nobody will
respond.

Basically, I cannot connect to port xxx for sending when I'm already
listening to it...

And my guess is that with the sequence I'm currenlty using...
- Connect to port  : Send query
- Close port 
- Listen to port 
...There is too much delay between switching from sending to listening
causing me to miss some of the initial UDP packets.

When running tests I can see 3 scenarios

Either :
(A) I get no packets at all. 
=> Ethereal shows for every response that was sent to me an ICMP that
reports "destination unreachable (Port unreachable)". Apparently the socket
is not yet listening...

Or

(B) I only get some of the packets. Usually the first few of the sequence
are missing (the UPnP device I'm currently using sends back 14 packets in
response to my discovery request). Strangely enough, Ethereal does not
report anymore that the "destination unreachable (Port unreachable)", but
TWSocket also does not make those initial packets available to me.

Or

(C) Sometimes everything works great and I get all packets sent to me (14 in
my test case, as confirmed by Ethereal).

I'm also wondering why sometimes OnDataAvailable is called when listening
but Receive() reports that the received length is -1.

SCENARIO A
- I get nothing back
- Ethereal shows for every response that was sent to me an ICMP that reports
"destination unreachable (Port unreachable)".
==
Send UDP : Send via port 1171
Send UDP : DONE. Close Socket
LISTEN UDP : listening on port 1171
Listen UDP for 5 seconds : DONE. Close Socket
  UDP with ReceiveLength >0 = [00]
  UDP with ReceiveLength <1 = [00]


SCENARIO B 
- only 11 out of 14 packets
- First 3 packets are missing, see scenario B
==
Send UDP : Send via port 1167
Send UDP : DONE. Close Socket
LISTEN UDP : listening on port 1167
UDP#01=ReceiveLen=249
UDP#02=ReceiveLen=283
UDP#03=ReceiveLen=249
UDP#04=ReceiveLen=283
UDP#05=ReceiveLen=261
UDP#06=ReceiveLen=309
UDP#07=ReceiveLen=296
UDP#08=ReceiveLen=313
UDP#09=ReceiveLen=315
UDP#10=ReceiveLen=305
UDP#11=ReceiveLen=305
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
  > UDP#**=ReceiveLen=-1
Listen UDP for 5 seconds : DONE. Close Socket
  UDP with ReceiveLength >0 = [11]
  UDP with ReceiveLength <1 = [10]


SCENARIO C 
- I get everything back nicely
==Send UDP : Send via port 1166
Send UDP : DONE. Close Socket
LISTEN UDP : listening on port 1166
UDP#01=ReceiveLen=232
UDP#02=ReceiveLen=243
UDP#03=ReceiveLen=304
UDP#04=ReceiveLen=249
UDP#05=ReceiveLen=283
UDP#06=ReceiveLen=249
UDP#07=ReceiveLen=283
UDP#08=ReceiveLen=261
UDP#09=ReceiveLen=309
UDP#10=ReceiveLen=296
UDP#11=ReceiveLen=313
UDP#12=ReceiveLen=315
UDP#13=ReceiveLen=305
UDP#14=ReceiveLen=305
Listen UDP for 5 seconds : DONE. Close Socket
  UDP with ReceiveLength >0 = [14]
  UDP with ReceiveLength <1 = [00]

Kris

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Angus Robertson - Magenta Systems Ltd
Sent: zondag 2 april 2006 18:56
To: twsocket@elists.org
Subject: Re: [twsocket] THttpCli and UPnP devices

> However, any subsequent attempts to use that same port for sending the 
> UDP packet fail. Only after closing the socket used for listening I 
> can use that port for sending a packet.

But that's not a problem is it?  Listen, connect, send query, wait x seconds
for responses, stop listen, repeat...

Does Windows not provide an API for UPnP discovery?  Certainly Windows
Vista, which I'm currently playing with, has Function Discovery interfaces
that do all this, Vista even found my Linksys wireless access point, mind it
didn't find a proper display adapter and Vista is really painful in VGA. 

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Arno Garrels
Angus Robertson - Magenta Systems Ltd wrote:
>> However, any subsequent attempts to use that same port for sending
>> the UDP packet fail. Only after closing the socket used for
>> listening I can use that port for sending a packet.
> 
> But that's not a problem is it?  Listen, connect, send query, wait x
> seconds for responses, stop listen, repeat...
> 
> Does Windows not provide an API for UPnP discovery?  Certainly Windows
> Vista, which I'm currently playing with, has Function Discovery
> interfaces that do all this, Vista even found my Linksys wireless access
> point, mind it didn't find a proper display adapter and Vista is really
> painful in VGA.

BTW: Don't you risk a lot if you enable UpnP devices? I was told it might be
a security hole, so I disabled them where I could in my LAN.

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html

-- 
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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Angus Robertson - Magenta Systems Ltd
> However, any subsequent attempts to use that same port for sending 
> the UDP packet fail. Only after closing the socket used for 
> listening I can use that port for sending a packet.

But that's not a problem is it?  Listen, connect, send query, wait x 
seconds for responses, stop listen, repeat...

Does Windows not provide an API for UPnP discovery?  Certainly Windows 
Vista, which I'm currently playing with, has Function Discovery 
interfaces that do all this, Vista even found my Linksys wireless access 
point, mind it didn't find a proper display adapter and Vista is really 
painful in VGA. 

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Kris Schoofs
I just tried your suggestion 

I used LocalPort-property to set a fixed port to open a socket for listening
first.

However, any subsequent attempts to use that same port for sending the UDP
packet fail. Only after closing the socket used for listening I can use that
port for sending a packet.

Kris
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Angus Robertson - Magenta Systems Ltd
Sent: zondag 2 april 2006 15:16
To: twsocket@elists.org
Subject: Re: [twsocket] THttpCli and UPnP devices

> I need to WSocket->Connect(); first because I need to know which port 
> will be used for sending

Can you not use the LocalPort property to specify a fixed port?

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Angus Robertson - Magenta Systems Ltd
> I need to WSocket->Connect(); first because I need to know which port 
> will be used for sending 

Can you not use the LocalPort property to specify a fixed port?

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Kris Schoofs
I need to WSocket->Connect(); first because I need to know which port will
be used for sending since this port will be the one where I'll be receiving
the response.

However, apparently you cannot combine a WSocket->Connect() and
WSocket->Listen() without doing a WSocket->Close() inbetween since this will
result in an "Address already in use"-exception.

Kris

 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Angus Robertson - Magenta Systems Ltd
Sent: zondag 2 april 2006 12:40
To: twsocket@elists.org
Subject: Re: [twsocket] THttpCli and UPnP devices

> Is it OK to close the socket after sending and then immediately open 
> it again for listening on that same port ?

You may get fast UDP responses, so I'd have thought it best to have a
listening port open before sending your request, but I've not tried sending
on a port already open for listening. 

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Angus Robertson - Magenta Systems Ltd
> Is it OK to close the socket after sending and then immediately open
> it again for listening on that same port ?

You may get fast UDP responses, so I'd have thought it best to have a 
listening port open before sending your request, but I've not tried 
sending on a port already open for listening. 

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


Re: [twsocket] THttpCli and UPnP devices

2006-04-02 Thread Kris Schoofs
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)
{
charBuffer[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


Re: [twsocket] THttpCli and UPnP devices

2006-03-30 Thread Angus Robertson - Magenta Systems Ltd
> 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


Re: [twsocket] THttpCli and UPnP devices

2006-03-30 Thread Dan
You will need to alter the HTTP component to use UDP.  I have used UPnP for 
port forwarding before but always used Windows XP NAT Traversal API rather 
than controlling devices manually.  Should be completely possible though.

Dan

- Original Message - 
From: <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 30, 2006 11:58 AM
Subject: [twsocket] THttpCli and UPnP devices


> Hi,
>
> 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.
>
> Any ideas if THttpCli can be used for this ?
>
> Thanks,
>
> Kris
> -- 
> 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


[twsocket] THttpCli and UPnP devices

2006-03-30 Thread Kris . Schoofs
Hi,

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.

Any ideas if THttpCli can be used for this ? 

Thanks,

Kris
-- 
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