Using 'read from socket' and 'write to socket'

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Moskito67
Posts: 8
Joined: Sun May 31, 2009 1:07 pm
Contact:

Using 'read from socket' and 'write to socket'

Post by Moskito67 » Sun May 31, 2009 2:16 pm

Hello,

When sending a Message to another Computer, using TCPIP Network, is it possible to send/receive french Characters ?
é è à for example are transformed to "bad" chars

Best Regards

Marc

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sun May 31, 2009 2:24 pm

Hi Marc,

I am not sure, but to be sure I, personally, would (and acually do)
URLENCODE all my strings before writing them to a socket!
Why tempt the fate? ;-)
...
put urlencode("é") -> %8E
...


Best

Klaus

Moskito67
Posts: 8
Joined: Sun May 31, 2009 1:07 pm
Contact:

thanks

Post by Moskito67 » Sun May 31, 2009 3:36 pm

this works fine
At reception, I then use:
replace "%8E" with "é" in data

Moskito67
Posts: 8
Joined: Sun May 31, 2009 1:07 pm
Contact:

Post by Moskito67 » Sun May 31, 2009 3:38 pm

Vielen Dank Klaus (von Strasbourg in France)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun May 31, 2009 3:59 pm

Dear Marc,

If you are establishing the connection yourself, using the "accept connections" and "open socket" commands, you can send any binary data you like. The data isn't really considered text if sent through a socket. It is simple "data" and your script turns it into something readable by reading the data from a socket and putting it into a field, for instance.

You really shouldn't use the replace function to decode a url. Instead, use the urlDecode function.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Moskito67
Posts: 8
Joined: Sun May 31, 2009 1:07 pm
Contact:

Post by Moskito67 » Sun May 31, 2009 4:24 pm

URLEncodind é on Windows -> %8E
and on MAC OSX -> %E9

So... it seems not possible to encode and then decode when PC is speaking to Mac !

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sun May 31, 2009 4:25 pm

Mark wrote:...
You really shouldn't use the replace function to decode a url. Instead, use the urlDecode function.

Best,

Mark
Exactement! :-)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun May 31, 2009 4:34 pm

Moskito67 wrote:URLEncodind é on Windows -> %8E
and on MAC OSX -> %E9

So... it seems not possible to encode and then decode when PC is speaking to Mac !
Dear Marc,

Whenever you send text from Mac to PC, you need to use the macToIso function to make the text readable on the PC. I believe the correct order is this:

put text from field into variable
put macToIso(variable) into variable
put urlEncode(variable) into variable
open socket
write variable to socket
close socket

accept connection
read from socket
close socket
put data into variable
put urlDecode(variable) into variabl
put text from variable into field

The above is only one of many possible approaches, but it should work.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Jun 03, 2009 9:20 am

Moskito67 wrote:URLEncodind é on Windows -> %8E
and on MAC OSX -> %E9

So... it seems not possible to encode and then decode when PC is speaking to Mac !
Welcome to the wonderful world of crossplatform development :-D

Well, I only SEEMS not to be possible!
As Makr already pointed out, you have to "convert" from mac to iso and vice versa if necessary...

The rest of the world ALWAYS uses the ISO format for strings, why not follow this convention?
I wrote two little functions that I use all the time for conterving text correctly whenever necessary:

Code: Select all

function mac2win tString

  ## We are on a Mac, so convert to ISO
  if the platform = "MacOS" then
    return mactoiso(tString)
  else

   ## We are NOT on a Mac, so no conversion necessary
    return tString
  end if
end mac2win

function win2mac tString
  if the platform = "MacOS" then
    return isotomac(tString)
  else
    return tString
  end if
end win2mac
You get the picture.


Best

Klaus

Moskito67
Posts: 8
Joined: Sun May 31, 2009 1:07 pm
Contact:

Post by Moskito67 » Wed Jun 03, 2009 9:35 am

Yes Klaus, I do it now and it works
(But not for all Chars, like €)

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Jun 03, 2009 9:56 am

Bonjour Moskito67,

yep, the Euro sign and some other characters are indeed a problem.

You could try to use HTML-text, that should be crossplatform (maybe not;-))

Like this:
<p>C'est une sign&eacute;e d'euro: &curren;.</p>

Should read (attention! mon français c'est incroyablement mauvais :-)) on all platforms
after setting the htmltext of a field to this string:
C'est une signée d'euro: €.


Au revoir

Klaus

Post Reply