Xojo.Net.TCPSocket

Hi Everyone,

I made an App with xojo and Tcpsocket to communicate between my computer and a micro controller.
I am trying to make the same one for my iPhone with IOS and Xojo.Net.TCPSocket.
I tried to use this code in the socket data available event :

dim msg As MemoryBlock msg=me.AvailableData 'ReadData(socket.BytesAvailable) t=xojo.core.TextEncoding.ascii.ConvertDataToText(msg) 't=t.Left(4) Ltemp.Text=t
When I use “available data” I get all the datas in the buffer but I cannot sort them.
If I use “left”, “right”, “mid” with text or memory block the App crashes.
I don’t see anything to flush the buffer after I get the datas from it?

When I use “ReadData(socket.BytesAvailable)”, I only get numbers and no word?

Thanks for your help.

Chris

In the documentation it is clearly stated that .BytesAvailable is the number of bytes available. Not the Available data itself.

AvailableData is the one to use. What do you mean with “I cannot sort them”?

Can you make a dummy project with the crash you’re having when using left, right or mid? It should work on a MemoryBlock, as there is an implicit cast to a string.

By the way, what ‘crash’ do you have? If the Data in AvailableData cannot be converted by ConvertDataToText you might have a runetimeException. Have you tried

t=xojo.core.TextEncoding.ascii.ConvertDataToText(msg, True)

?

dim msg As MemoryBlock msg=me.ReadData(10) t=xojo.core.TextEncoding.ascii.ConvertDataToText(msg) 't=t.Left(4) Ltemp.Text=t
This does not work either, I only get number without letters.

dim msg As MemoryBlock msg=me.AvailableData t=xojo.core.TextEncoding.ascii.ConvertDataToText(msg) Ltemp.Text=t
With the code above, it works, it crashes when I use the code below :

dim msg As MemoryBlock msg=me.AvailableData msg=msg.Right(4) t=xojo.core.TextEncoding.ascii.ConvertDataToText(msg) Ltemp.Text=t

Thanks

Chris

dim t as text
then try to replace ASCII -> UTF8 regarding to TextEncoding and see if will do a job.

I also tried UTF8, doesn’t make a difference.
I find a solution to make it work.
I use a timer and I disconnect and connect the socket every 5 seconds, this way I “flush” the buffer and I can read the information I need.
I am still curious to know why left, right, etc, don’t work and crash?

Thanks for your help

Chris