Hey carl, Say hi to Jeff Long for me! I was working on something similar to this around Christmas. I didn't get quite as far as you, but I was using a very different approach. I tried modifying the sample code for the chat server to function with l2cap, and more recently to do cross linux- mac communication over RFCOMM (using the sample app again). The l2cap chat program worked well for me on multiple Macs, and even supporting multiple simultaneous connections... sortof. I noticed in your code your calling the openL2CAPChannel and then setting a delegate.. might be better to try and use the openL2CAPChannelSync Call. I also found that the chat client sample code wasn't to bad to work with. I can send you my adapted for l2cap stuff if you want. (Although I yesterday I moved my linux mac into the lab where I am testing the work I am doing.. so I can't try the code out.. or clean it up.) Working with RFComms on linux and the mac is not to bad. The only problem, is that the linux standard RFCOMM listener seems to repeat all the data sent on the channel back to the sender one character at a time. For my uses this didn't matter since I only wanted a one way channel. Did you set up an SDP record on the linux box for your service? Best of luck! Alex On 8-Mar-04, at 2:42 PM, Carl Norum wrote:
Hi there! I'm trying to get some simple bluetooth apps working. I've
written an L2CAP based text chat program for linux using the BlueZ
stack, and now I'm trying to write a Mac OS X client to connect to it
as well.
At the beginning everything works fine; I can connect to the linux box
using the following code:
NSAutoreleasePool *mainPool;
int main (int argc, const char *argv[])
{
IOBluetoothDevice *dev;
BluetoothDeviceAddress btAddr;
IOBluetoothL2CAPChannel *channel;
IOReturn err;
ChatDelegate *interface;
mainPool = [[NSAutoreleasePool alloc] init];
interface = [[ChatDelegate alloc] init];
IOBluetoothNSStringToDeviceAddress(@"00:04:76:C8:40:B0", &btAddr);
dev = [IOBluetoothDevice withAddress:&btAddr];
err = [dev openL2CAPChannel:kBluetoothL2CAPPSMRFCOMM
findExisting:FALSE newChannel:&channel];
NSLog(@"openL2CAPChannel: 0x%08x", err);
if (err != kIOReturnSuccess)
exit(0);
[channel setDelegate:interface];
[[NSRunLoop currentRunLoop] run];
return 0;
}
The ChatDelegate code looks like this:
- (void)sender:(IOBluetoothL2CAPChannel *)channel
{
IOReturn err;
senderPool = [[NSAutoreleasePool alloc] init];
char buffer[BUFFER_SIZE];
do {
fgets(buffer, BUFFER_SIZE, stdin);
err = [channel writeSync:buffer length:strlen(buffer) + 1];
NSLog(@"Return: 0x%0x String: %s", err, buffer);
} while (strcmp(buffer, ".\n") != 0);
[channel closeChannel];
[senderPool release];
[mainPool release];
exit(0);
}
- (void)l2capChannelData:(IOBluetoothL2CAPChannel*)l2capChannel
data:(void *)dataPointer length:(size_t)dataLength
{
NSLog(@"Data received");
printf(dataPointer);
if (strcmp(dataPointer, ".\n") == 0) {
[l2capChannel closeChannel];
[senderPool release];
[mainPool release];
exit(0);
}
}
-
(void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel
status:(IOReturn)error
{
NSLog(@"Channel Open Complete: 0x%x", error);
if (error == kIOReturnSuccess)
[NSThread detachNewThreadSelector:@selector(sender:)
toTarget:self withObject:l2capChannel];
}
The connection appears to work successfully - I get my @"Channel Open
Complete" message fine, and the linux box prints out "Connection
Accepted" after the accept() call returns. However, data sending and
receiving appears not to work. Anything I type in on the linux box
causes a successful return from send(), but nothing shows up on the
Mac via l2capChannelData:data:length. Likewise, anything entered on
the mac (from sender:) doesn't get sent - I get an IOReturn error
indicating kIOReturnNotPrivileged. Why does this happen? Any
thoughts, ideas, better ways to do this? I'm just getting started
with bluetooth, so I may be making terrible errors.
Thanks everyone!
--
Carl J Norum
Academic Director, IEEE NSS Student Branch
Final Year Electrical Engineering/Computer Science Student
University of Saskatchewan
Saskatoon, Canada
_______________________________________________
bluetooth-dev mailing list | bluetooth-dev@lists.apple.com
Help/Unsubscribe/Archives:
Do not post admin requests to the list. They will be ignored.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s] _______________________________________________ bluetooth-dev mailing list | bluetooth-dev@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/bluetooth-dev Do not post admin requests to the list. They will be ignored.