11-30-2009 04:25 AM
it's a it difficult to describe this problem but i'll try
i'm trying to create a socket connection with an external server that comunicates with some packets with a defined structure. First to this server i send an array of 8 bytes to start the comunication, i receive an ack then i send the real packet with date, hour and some gps coordinates.
the problem is that i don't know what the socket sends.
i'll explain with a little example.
i have to send a string of 8 chars that i transform in bytes (just a simple type cast is needed) i put these bytes in the byte array then i send it to the socket but the server doesn't send the ack (the server is ok it sends the ack to other application but these applications aren't java's applications) so the problem is what i really send to the server.
i've tried to create a file to look what i send and i found that the bytes are transformed to decimals and this is fine for me but when i tried to write the bytes on the BB's screen i saw that the "string" is completely different of what i expect.
as socket i've used one that i've created some time ago it worked fine but that time it used a local server
i hope that somebody understands what i've said..
p.s. i have to use a byte array and i can't use just strings
11-30-2009 04:29 AM
Best would be to use a sniffer tool to check what is sent to the server. I recommend wireshark (formerly known as ethereal).
Just run it on the BES or better test on simulator and let it run locally.
How are you writing to the socket? Can you post the code?
11-30-2009 04:48 AM
we were trying to see what i'm sending to the server but we aren't lucky...now i'll try with the sniffer
the socket is a basic one beacause for the moment is a kind of test
11-30-2009 05:24 AM
Try using a flush after writing to the outputstream.
Just a comment: you can only send ascii characters this way. Better would be to use one of getBytes methods from the string instead of casting chars to bytes
11-30-2009 05:47 AM
the flush doesn't help
i know i can use the getbytes, but i can use it only for the first packet after that i can't use it because the next array of bytes hasn't only chars but also int and short.
By "you can only send ascii characters this way" you mean that the outputstream sends to the server ascii characters?
if yes, how can i send to the server non-ascii characters?
11-30-2009 07:45 AM
> By "you can only send ascii characters this way" you mean that the outputstream sends to the server ascii characters?
No I was just refering to the cast from characters to bytes which only works for ascii characters.
11-30-2009 09:35 AM
ok...but it's not the problem
by the way the socket is defined right? and the output/input streams are ok? (maybe there's an error that i can't find...)
11-30-2009 12:29 PM
As long as your url starts with "socket://" everything looks fine to me.
Any updates on the data that was sent?
12-01-2009 05:09 AM
I think you need to split this into two different problems:
a) Getting the data correct
I suggest that you create and test independently a routine that will convert your Vector entry in a byte array. I'm not convinced about some of this code and you write the entire length of the buffer regardless of how much is actually used. You can do this yourself, it is easy to write a test and use the debugger to check this. I don't think you need our help with this.
b) Sending the information on the socket.
Rewrite the above to just send bytes that you specify. For example one easy thing to do is
byte  testSend = "0123456789ABCDEF".getBytes();
Then you can test your socket code independently.
Once you have rewritten this and have a much smaller code snippet, if you are still having problems can you repost the smaller section of code. That will make it easier for us to understand and test ourselves if we want to.
In addition, there seems to be to be a flaw in your design. I would recommend that you send one entry from your Vector, and only delete it when you have received an acknowledgement that it has been successfully received. The code at present will process all entries (which might overflow your buffer) and may not even send them, meaning you have lost your co-ordinates.
12-01-2009 05:22 AM
yes the url stars with "socket://"
i've found that there was some connection problems but trying with the socket of the SocketDemo a i can connect to the server but it says that the comunication protocol il wrong...i have to send UB000001 as an "hello" to the server, but the servers log says that i send all zeros...so i can't send the packet with the gps' coordinates....