2006-02-27 01:29:09

by Deniz Demir

[permalink] [raw]
Subject: [Bluez-devel] RFCOMM Server: accept does not block

Hi,

I want to run a small rfcomm server, however it does not block on
accept, and returns immediately with -1 as socket descriptor (last
line prints -1 right away).

I have the following code:

// allocate socket
s =3D socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// bind socket to port 1 of the first available
// local bluetooth adapter
loc_addr.rc_family =3D AF_BLUETOOTH;
loc_addr.rc_bdaddr =3D *BDADDR_ANY;
loc_addr.rc_channel =3D (uint8_t) 1;
bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

// put socket into listening mode
listen(s, 1);

// accept one connection
client =3D accept(s, (struct sockaddr *)&rem_addr, &opt);
printf("client: %d \n", client);

I expected it would block on accept function until a connection
request came in. I appreciate any comments.

Thanks,
Deniz


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel


2006-02-27 04:14:58

by Deniz Demir

[permalink] [raw]
Subject: Re: [Bluez-devel] RFCOMM Server: accept does not block

Thanks Albert.

It was conflicting port assigment. In fact, I had changed the port,
however, I mistyped in one place. Anyway, it is okay now.

-Deniz

On 2/26/06, Albert Huang <[email protected]> wrote:
> one of the other socket functions probably failed. check the return code=
s
> for all socket calls (a good practice in general) and use perror again. =
You
> may also want to read through that entire guide if you're not familiar wi=
th
> socket programming.
>
> -albert
>
>
> On 2/26/06, Deniz Demir <[email protected]> wrote:
> >
> > Thank you Albert.
> >
> > perror reports the following error message:
> >
> > socket: File descriptor in bad state
> >
> >
> > On 2/26/06, Albert Huang <[email protected]> wrote:
> > > Use perror to find out what went wrong.
> > >
> > > http://beej.us/guide/bgnet/output/html/errnoman.html
> > >
> > > -albert
> > >
> > >
> > > On 2/26/06, Deniz Demir <[email protected]> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I want to run a small rfcomm server, however it does not block on
> > > > accept, and returns immediately with -1 as socket descriptor (last
> > > > line prints -1 right away).
> > > >
> > > > I have the following code:
> > > >
> > > > // allocate socket
> > > > s =3D socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
> > > >
> > > > // bind socket to port 1 of the first available
> > > > // local bluetooth adapter
> > > > loc_addr.rc_family =3D AF_BLUETOOTH;
> > > > loc_addr.rc_bdaddr =3D *BDADDR_ANY;
> > > > loc_addr.rc_channel =3D (uint8_t) 1;
> > > > bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
> > > >
> > > > // put socket into listening mode
> > > > listen(s, 1);
> > > >
> > > > // accept one connection
> > > > client =3D accept(s, (struct sockaddr *)&rem_addr, &opt);
> > > > printf("client: %d \n", client);
> > > >
> > > > I expected it would block on accept function until a connection
> > > > request came in. I appreciate any comments.
> > > >
> > > > Thanks,
> > > > Deniz
> > > >
> > > >
> > > >
> -------------------------------------------------------
> > > > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> > > language
> > > > that extends applications into web and mobile media. Attend the liv=
e
> > > webcast
> > > > and join the prime developer group breaking into this new coding
> > > territory!
> > > >
> > >
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642
> > > > _______________________________________________
> > > > Bluez-devel mailing list
> > > > [email protected]
> > > >
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
> > > >
> > >
> > >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> > that extends applications into web and mobile media. Attend the live
> webcast
> > and join the prime developer group breaking into this new coding
> territory!
> >
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642
> > _______________________________________________
> > Bluez-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-02-27 03:23:15

by Albert Huang

[permalink] [raw]
Subject: Re: [Bluez-devel] RFCOMM Server: accept does not block

one of the other socket functions probably failed. check the return codes
for all socket calls (a good practice in general) and use perror again. You
may also want to read through that entire guide if you're not familiar with
socket programming.

-albert

On 2/26/06, Deniz Demir <[email protected]> wrote:
>
> Thank you Albert.
>
> perror reports the following error message:
>
> socket: File descriptor in bad state
>
>
> On 2/26/06, Albert Huang <[email protected]> wrote:
> > Use perror to find out what went wrong.
> >
> > http://beej.us/guide/bgnet/output/html/errnoman.html
> >
> > -albert
> >
> >
> > On 2/26/06, Deniz Demir <[email protected]> wrote:
> > >
> > > Hi,
> > >
> > > I want to run a small rfcomm server, however it does not block on
> > > accept, and returns immediately with -1 as socket descriptor (last
> > > line prints -1 right away).
> > >
> > > I have the following code:
> > >
> > > // allocate socket
> > > s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
> > >
> > > // bind socket to port 1 of the first available
> > > // local bluetooth adapter
> > > loc_addr.rc_family = AF_BLUETOOTH;
> > > loc_addr.rc_bdaddr = *BDADDR_ANY;
> > > loc_addr.rc_channel = (uint8_t) 1;
> > > bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
> > >
> > > // put socket into listening mode
> > > listen(s, 1);
> > >
> > > // accept one connection
> > > client = accept(s, (struct sockaddr *)&rem_addr, &opt);
> > > printf("client: %d \n", client);
> > >
> > > I expected it would block on accept function until a connection
> > > request came in. I appreciate any comments.
> > >
> > > Thanks,
> > > Deniz
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> > language
> > > that extends applications into web and mobile media. Attend the live
> > webcast
> > > and join the prime developer group breaking into this new coding
> > territory!
> > >
> > http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
> > > _______________________________________________
> > > Bluez-devel mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> > >
> >
> >
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> that extends applications into web and mobile media. Attend the live
> webcast
> and join the prime developer group breaking into this new coding
> territory!
> http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


Attachments:
(No filename) (2.78 kB)
(No filename) (4.35 kB)
Download all attachments

2006-02-27 02:39:36

by Deniz Demir

[permalink] [raw]
Subject: Re: [Bluez-devel] RFCOMM Server: accept does not block

Thank you Albert.

perror reports the following error message:

socket: File descriptor in bad state


On 2/26/06, Albert Huang <[email protected]> wrote:
> Use perror to find out what went wrong.
>
> http://beej.us/guide/bgnet/output/html/errnoman.html
>
> -albert
>
>
> On 2/26/06, Deniz Demir <[email protected]> wrote:
> >
> > Hi,
> >
> > I want to run a small rfcomm server, however it does not block on
> > accept, and returns immediately with -1 as socket descriptor (last
> > line prints -1 right away).
> >
> > I have the following code:
> >
> > // allocate socket
> > s =3D socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
> >
> > // bind socket to port 1 of the first available
> > // local bluetooth adapter
> > loc_addr.rc_family =3D AF_BLUETOOTH;
> > loc_addr.rc_bdaddr =3D *BDADDR_ANY;
> > loc_addr.rc_channel =3D (uint8_t) 1;
> > bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
> >
> > // put socket into listening mode
> > listen(s, 1);
> >
> > // accept one connection
> > client =3D accept(s, (struct sockaddr *)&rem_addr, &opt);
> > printf("client: %d \n", client);
> >
> > I expected it would block on accept function until a connection
> > request came in. I appreciate any comments.
> >
> > Thanks,
> > Deniz
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> > that extends applications into web and mobile media. Attend the live
> webcast
> > and join the prime developer group breaking into this new coding
> territory!
> >
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642
> > _______________________________________________
> > Bluez-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2006-02-27 02:08:00

by Albert Huang

[permalink] [raw]
Subject: Re: [Bluez-devel] RFCOMM Server: accept does not block

Use perror to find out what went wrong.

http://beej.us/guide/bgnet/output/html/errnoman.html

-albert

On 2/26/06, Deniz Demir <[email protected]> wrote:
>
> Hi,
>
> I want to run a small rfcomm server, however it does not block on
> accept, and returns immediately with -1 as socket descriptor (last
> line prints -1 right away).
>
> I have the following code:
>
> // allocate socket
> s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
>
> // bind socket to port 1 of the first available
> // local bluetooth adapter
> loc_addr.rc_family = AF_BLUETOOTH;
> loc_addr.rc_bdaddr = *BDADDR_ANY;
> loc_addr.rc_channel = (uint8_t) 1;
> bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
>
> // put socket into listening mode
> listen(s, 1);
>
> // accept one connection
> client = accept(s, (struct sockaddr *)&rem_addr, &opt);
> printf("client: %d \n", client);
>
> I expected it would block on accept function until a connection
> request came in. I appreciate any comments.
>
> Thanks,
> Deniz
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> that extends applications into web and mobile media. Attend the live
> webcast
> and join the prime developer group breaking into this new coding
> territory!
> http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


Attachments:
(No filename) (1.57 kB)
(No filename) (2.46 kB)
Download all attachments