Sign in to follow this  
Followers 0
Info

TCP functions with unicode characters

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to send Hebrew characters in TCP and then add the data to a tree view.

server:

TCPStartup()

$listen = TCPListen(@IPAddress1,2000)

GUICreate("")
$tree = GUICtrlCreateTreeView(0, 0, 300, 300)
GUISetState()

While 1
    $accept = TCPAccept($listen)
    If $accept <> -1 Then
        ExitLoop
    EndIf
    
    
    If GUIGetMsg() = -3 Then
        Exit
    EndIf
WEnd
ToolTip("accepted")

While 1
    $tcpRecv = TCPRecv($accept, 1000000,1)
    If $tcpRecv <> "" Then
        ExitLoop
    EndIf
    
    
    If GUIGetMsg() = -3 Then
        Exit
    EndIf
WEnd
ToolTip("received")

GUICtrlCreateTreeViewItem("1: " & BinaryToString($tcpRecv,1),$tree)
GUICtrlCreateTreeViewItem("2: " & BinaryToString($tcpRecv,2),$tree)
GUICtrlCreateTreeViewItem("3: " & BinaryToString($tcpRecv,3),$tree)
GUICtrlCreateTreeViewItem("4: " & BinaryToString($tcpRecv,4),$tree)

GUICtrlCreateTreeViewItem("עברית: שדגשדג",$tree) ;just to see if Hebrew characters actually display
TCPCloseSocket($accept)
While 1
    If GUIGetMsg() = -3 Then
        Exit
    EndIf
WEnd

TCPShutdown()

client:

TCPStartup()
$con = TCPConnect(@IPAddress1,2000)
If @error Then
    MsgBox(0,0,"could not connect")
    Exit
EndIf

TCPSend($con,Binary("א ב ג ד ה ו א ב ג ד ה ו"))
;TCPSend($con,Binary("asdasd"))
Sleep(100)
TCPShutdown()

Result:

Posted Image

Any suggestions?

Edited by Info

Share this post


Link to post
Share on other sites



hi info,

When sending the data, use

StringToBinary("your Hebrew chars",4) ;to encode as UTF8

and when receiving use

BinaryToString($bPacket,4) ;to decode as UTF8

Hope this helps :unsure:

-smartee

Share this post


Link to post
Share on other sites

Works! thanks!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0