* [Bluez-devel] Problem with read on RFCOMM Sockets
@ 2004-06-15 18:31 ionut dediu
2004-06-15 22:49 ` Marcel Holtmann
0 siblings, 1 reply; 6+ messages in thread
From: ionut dediu @ 2004-06-15 18:31 UTC (permalink / raw)
To: bluez-devel
Hy
I have a Fedora linux running kernel 2.6.5-1.358. I
made a simple client program on the PC which reads
data sent from a Phone Server application through
rfcomm. Read allways returns the correct no of bytes,
but the buffer in which I read allways has just 1 byte
of data. I saw from another post that there were
similar problems with rfcomm sockets, and as I
understand this could be a kernel bug. Could you tell
me what upgrade should I make to the kernel ? Thanks a
lot in advance.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Problem with read on RFCOMM Sockets
2004-06-15 18:31 ionut dediu
@ 2004-06-15 22:49 ` Marcel Holtmann
2004-06-16 11:11 ` ionut dediu
0 siblings, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2004-06-15 22:49 UTC (permalink / raw)
To: ionut dediu; +Cc: BlueZ Mailing List
Hi,
> I have a Fedora linux running kernel 2.6.5-1.358. I
> made a simple client program on the PC which reads
> data sent from a Phone Server application through
> rfcomm. Read allways returns the correct no of bytes,
> but the buffer in which I read allways has just 1 byte
> of data. I saw from another post that there were
> similar problems with rfcomm sockets, and as I
> understand this could be a kernel bug. Could you tell
> me what upgrade should I make to the kernel ?
show us your source code.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Problem with read on RFCOMM Sockets
2004-06-15 22:49 ` Marcel Holtmann
@ 2004-06-16 11:11 ` ionut dediu
2004-06-16 11:32 ` Marcel Holtmann
0 siblings, 1 reply; 6+ messages in thread
From: ionut dediu @ 2004-06-16 11:11 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: bluez-devel
Hi
Here is the source code. For testing the receiving of
data I tried commenting the select loop, and do just
receiveData, and I get the same results: read returns
the correct number of bytes, but in the buffer is
copied just one byte of data. Please tell me if I'm
doing smth wrong. Thanks a lot.
#include <unistd.h>
#include <syslog.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#define BT_LOCAL_ADDR "00:0C:76:D3:4C:D3"
#define BT_REM_NOKIA_ADDR "00:60:57:D2:27:66"
#define DIM 256
#define STDIN 0
#define STDOUT 1
char userBuf[DIM];
char remoteBuf[DIM];
int clientSocket = 0;
int do_connect(char * remAddr)
{
struct sockaddr_rc rem_addr, loc_addr;
int s;
if ((s = socket(PF_BLUETOOTH, SOCK_STREAM,
BTPROTO_RFCOMM)) < 0) {
syslog(LOG_ERR, "Can't create socket. %s(%d)",
strerror(errno), errno);
return -1;
}
memset(&loc_addr, 0, sizeof(loc_addr));
loc_addr.rc_family = AF_BLUETOOTH;
str2ba(BT_LOCAL_ADDR, &loc_addr.rc_bdaddr);
if (bind(s, (struct sockaddr *) &loc_addr,
sizeof(loc_addr)) < 0) {
printf("Can't bind socket. %s(%d)", strerror(errno),
errno);
exit(1);
}
memset(&rem_addr, 0, sizeof(rem_addr));
rem_addr.rc_family = AF_BLUETOOTH;
baswap(&rem_addr.rc_bdaddr, strtoba(remAddr));
rem_addr.rc_channel = 4;
if (connect(s, (struct sockaddr *)&rem_addr,
sizeof(rem_addr)) < 0 ) {
printf("Can't connect. %s(%d)\n", strerror(errno),
errno);
close(s);
return -1;
}
printf("Connected\n");
return s;
}
int receiveData()
{
int noBytesRead = 0;
memset(remoteBuf, 0, DIM);
noBytesRead = read(clientSocket, remoteBuf, DIM);
if(noBytesRead == -1)
{
printf("Can't read. %s(%d)\n", strerror(errno),
errno);
exit(-1);
}
if(noBytesRead == 0)
{
printf("Disconnected\n");
exit(0);
}
printf("REMOTE[%d](strlen = %d) : %s\n", noBytesRead,
strlen(remoteBuf), remoteBuf);
return noBytesRead;
// write(STDOUT, buf, strlen(buf));
}
int sendData()
{
memset(userBuf, 0, DIM);
read(STDIN, userBuf, DIM);
if(write(clientSocket, userBuf, strlen(userBuf)) !=
strlen(userBuf))
{
printf("Can't write. %s(%d)\n", strerror(errno),
errno);
return -1;
}
return 0;
}
int main(int argc, char** argv)
{
fd_set read_fds; //fd_set used in select()
fd_set tmp_fds; //fd_set temporary fds
int fdmax; //maximum no of file descriptors
int i = 0;
clientSocket = do_connect(BT_REM_NOKIA_ADDR);
FD_SET(clientSocket, &read_fds);
FD_SET(STDIN, &read_fds);
fdmax = clientSocket;
/* while(1)
{
receiveData();
}*/
// main loop
while(1)
{
tmp_fds = read_fds;
if(select(fdmax + 1, &tmp_fds, NULL, NULL, NULL) ==
-1)
{
printf("ERROR in select. %s(%d)\n",
strerror(errno), errno);
exit(errno);
}
else
{
for(i = 0; i <= fdmax; i++)
{
if(FD_ISSET(i, &tmp_fds))
{
// received data from the bluetooth end point
if(i == clientSocket)
{
receiveData();
}
// received input data from the user
if(i == STDIN)
{
sendData();
}
}
}
}
}
close (clientSocket);
return 0;
}
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Problem with read on RFCOMM Sockets
2004-06-16 11:11 ` ionut dediu
@ 2004-06-16 11:32 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2004-06-16 11:32 UTC (permalink / raw)
To: ionut dediu; +Cc: BlueZ Mailing List
Hi,
> Here is the source code. For testing the receiving of
> data I tried commenting the select loop, and do just
> receiveData, and I get the same results: read returns
> the correct number of bytes, but in the buffer is
> copied just one byte of data. Please tell me if I'm
> doing smth wrong. Thanks a lot.
your buffer should be "unsigned char" and you shouldn't use strlen() to
check to length of your buffer. Rely on the return value of read().
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Bluez-devel] Problem with read on RFCOMM Sockets
@ 2004-06-16 13:17 Williams, Richard
2004-06-16 13:27 ` Marcel Holtmann
0 siblings, 1 reply; 6+ messages in thread
From: Williams, Richard @ 2004-06-16 13:17 UTC (permalink / raw)
To: BlueZ Mailing List
I understand why strlen should not be used in this case, but why
unsigned char instead of char ? There are many examples of the=20
use of the generic file I/O read() function in the literature=20
using char buffers. Is this case different ?
thanks, Best regards,
Rich
Hi,
> Here is the source code. For testing the receiving of
> data I tried commenting the select loop, and do just
> receiveData, and I get the same results: read returns
> the correct number of bytes, but in the buffer is
> copied just one byte of data. Please tell me if I'm
> doing smth wrong. Thanks a lot.
your buffer should be "unsigned char" and you shouldn't use strlen() to
check to length of your buffer. Rely on the return value of read().
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Bluez-devel] Problem with read on RFCOMM Sockets
2004-06-16 13:17 [Bluez-devel] Problem with read on RFCOMM Sockets Williams, Richard
@ 2004-06-16 13:27 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2004-06-16 13:27 UTC (permalink / raw)
To: Williams, Richard; +Cc: BlueZ Mailing List
Hi Richard,
> I understand why strlen should not be used in this case, but why
> unsigned char instead of char ? There are many examples of the
> use of the generic file I/O read() function in the literature
> using char buffers. Is this case different ?
it actually depends on the other side. If the other side also uses char
then there should be no problem, but it is better to use unsigned char
if you don't know what the other side is sending.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-06-16 13:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-16 13:17 [Bluez-devel] Problem with read on RFCOMM Sockets Williams, Richard
2004-06-16 13:27 ` Marcel Holtmann
-- strict thread matches above, loose matches on Subject: below --
2004-06-15 18:31 ionut dediu
2004-06-15 22:49 ` Marcel Holtmann
2004-06-16 11:11 ` ionut dediu
2004-06-16 11:32 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox