2005-04-15 18:01:02

by Marco Trudel

[permalink] [raw]
Subject: [Bluez-users] reconnect if a remote device quits

Hello everybody

I connect from a PC to another like this:
sock = socket(...)
bind(sock, ...)
connect(sock, ...)
// here the data is exchanged


I now wish to automatic reconnect if the other PC closes the connection
(reboot for example), so I do:

while(true)
{
sock = socket(...)
bind(sock, ...)
connect(sock, ...)
// here the data is exchanged until the remote device quits
sleep(a little);
}

this works fine. but actually i expected this to be enough:

sock = socket(...)
bind(sock, ...)
while(true)
{
connect(sock, ...)
// here the data is exchanged
sleep(a little);
}

but this won't reconnect...
why is socket() and bind() required again? don't they stay the same if I
try to connect to the same bluetooth device again?


regards
Marco


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users


2005-04-15 23:21:15

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-users] reconnect if a remote device quits

Hi Marco,

> I connect from a PC to another like this:
> sock = socket(...)
> bind(sock, ...)
> connect(sock, ...)
> // here the data is exchanged
>
>
> I now wish to automatic reconnect if the other PC closes the connection
> (reboot for example), so I do:
>
> while(true)
> {
> sock = socket(...)
> bind(sock, ...)
> connect(sock, ...)
> // here the data is exchanged until the remote device quits
> sleep(a little);
> }
>
> this works fine. but actually i expected this to be enough:
>
> sock = socket(...)
> bind(sock, ...)
> while(true)
> {
> connect(sock, ...)
> // here the data is exchanged
> sleep(a little);
> }
>
> but this won't reconnect...
> why is socket() and bind() required again? don't they stay the same if I
> try to connect to the same bluetooth device again?

you need to do the full stuff, because close() means closed.

Regards

Marcel




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users