dtnghia
Posts: 24
Joined: Thu Sep 18, 2008 8:54 pm
Location: Vietnam

Send text message vi OBEX Object Push

Mon Oct 20, 2008 8:57 pm

Hi,

I created obex object push and start it. Then i refer the code in help file to send message to service, the code is:

private void writeToStream(System.IO.Stream selectedStream, string textToWrite)
{
if(selectedStream != null)
{
char[] charWrite = textToWrite.ToCharArray();
byte[] byteWrite = new byte[charWrite.Length];

for(int inx = 0; inx < charWrite.Length; inx++)
{
byteWrite[inx] = (byte) charWrite[inx];
}
selectedStream.BeginWrite(byteWrite, 0, byteWrite.Length, new AsyncCallback(writeCallback), selectedStream);
}
else
{
MessageBox.Show("Select a session first");
}
}

private void writeCallback(IAsyncResult result)
{
System.IO.Stream selectedStream = (System.IO.Stream) result.AsyncState;

// EndWrite() must always be called if BeginWrite() was used!
selectedStream.EndWrite(result);
}

But one service, it throws exception in header of received packet.
Please help me!!!. Thanks

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Send text message vi OBEX Object Push

Mon Oct 20, 2008 9:22 pm

I'm not sure what you are trying to do, the Obex protocol is strict and requires you to send specific bytes in specific order to tell it what you want it to do (login,logout,send a file, get a file etc)

ObjectPushClient is a client sample that shows how to use the Obex component to push a file onto an Obex Object Push service.
ObexService is a sample that shows how to use the Obex component as a server.

None of these are 100% since the Obex protocol (while strict) is implemented a little differently on different platforms (cell phones, computers, Pocket PCs). The client usually works without a hassle but the service can't handle every contingency a client might throw at it.

If you wish to expand on the component the source is available here: http://www.franson.com/bluetools/download.asp?platform=net

Regards,
Jonas

dtnghia
Posts: 24
Joined: Thu Sep 18, 2008 8:54 pm
Location: Vietnam

RE: Send text message vi OBEX Object Push

Wed Oct 22, 2008 1:00 pm

Hi Jonas,

Thanks for your info. I will try it

dtnghia
Posts: 24
Joined: Thu Sep 18, 2008 8:54 pm
Location: Vietnam

RE: Send text message vi OBEX Object Push

Thu Oct 23, 2008 9:08 am

Hi Jonas,

I create mobile application ( java) for OBEX Server with PUT Operation code as:
public int onPut (Operation op) {

try {
java.io.InputStream is = op.openInputStream();

updateStatus("Got data bytes " + is.available() + " name " + op.getReceivedHeaders().getHeader(HeaderSet.NAME) + " type " + op.getType());

File f = new File((String)op.getReceivedHeaders().getHeader(HeaderSet.NAME));
FileOutputStream fos = new FileOutputStream (f);
byte b[] = new byte[1000];
int len;

while (is.available() > 0 && (len = is.read(b)) > 0) {
fos.write (b, 0, len);
}

fos.close();
updateStatus("[server:] Wrote data to " + f.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
}

return ResponseCodes.OBEX_HTTP_OK;
}


And then i create .NET application for client, client will send file to server with code:
m_objectPush.PushFile(fileStream, "send.txt", currentStream)
( i just quote this line, entire codes are extract from your example).

and it throw error: " Remote Obex service answered something we did not understand. (43)".

Please help me

Thanks

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Send text message vi OBEX Object Push

Thu Oct 23, 2008 9:14 am

You are basically answering something the client isn't expecting, just as it says.
I don't see that you answer anything at all in your server. I suggest that you get hold of a copy of the Obex specification if you are planning to build your own Obex server and have a look on what response codes you are supposed to answer.

Regards,
Jonas

dtnghia
Posts: 24
Joined: Thu Sep 18, 2008 8:54 pm
Location: Vietnam

RE: Send text message vi OBEX Object Push

Sat Nov 01, 2008 7:28 am

Hi Jonas,

Thanks for your advice. Now i created Serial Port Service as Client device and use code lines below to send data:

......
DataStream selectedStream = new DataStream(currentStream);
selectedStream.BeginWrite(bytes, 0, bytes.Length, new AsyncCallback(wCallback), selectedStream);

private void wCallback(IAsyncResult result)
{
System.IO.Stream selectedStream = (System.IO.Stream)result.AsyncState;

selectedStream.EndWrite(result);
selectedStream.Close();

}

And i face problems as:

If i put break points at BeginWrite function and wCallback, the sending is successful. But if i dont put, the sending is fail at client.

Please help me.

Thanks

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Send text message vi OBEX Object Push

Sat Nov 01, 2008 3:49 pm

You are connecting to the SerialPort service instead of the Obex service so I am really at a loss?

Regards,
Jonas

Return to “BlueTools”