Page 1 of 1

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

Posted: Sun May 31, 2009 2:16 pm
by Moskito67
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

Posted: Sun May 31, 2009 2:24 pm
by Klaus
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

thanks

Posted: Sun May 31, 2009 3:36 pm
by Moskito67
this works fine
At reception, I then use:
replace "%8E" with "é" in data

Posted: Sun May 31, 2009 3:38 pm
by Moskito67
Vielen Dank Klaus (von Strasbourg in France)

Posted: Sun May 31, 2009 3:59 pm
by Mark
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

Posted: Sun May 31, 2009 4:24 pm
by Moskito67
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 !

Posted: Sun May 31, 2009 4:25 pm
by Klaus
Mark wrote:...
You really shouldn't use the replace function to decode a url. Instead, use the urlDecode function.

Best,

Mark
Exactement! :-)

Posted: Sun May 31, 2009 4:34 pm
by Mark
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

Posted: Wed Jun 03, 2009 9:20 am
by Klaus
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

Posted: Wed Jun 03, 2009 9:35 am
by Moskito67
Yes Klaus, I do it now and it works
(But not for all Chars, like €)

Posted: Wed Jun 03, 2009 9:56 am
by Klaus
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