Jump to content
Sign in to follow this  
GreenBox

tcpsend error...

Recommended Posts

GreenBox

This code will work fine in ansi.

But, i run unicode, it is well error.

it well be not work.

#AutoIt3Wrapper_UseAnsi=n

TCPStartup()
Local $Chk = _TCPChack("안녕하세요? 이것은 테스트입니다." & @CRLF & "TEST 01234567890123456789")
MsgBox(64, "Send Message", $Chk[0][0])
MsgBox(64, "Recv Message", $Chk[1][0])
If $Chk[0][1] = $Chk[1][1] Then
    Local $Ck = 64
Else
    Local $Ck = 16
EndIf
MsgBox($Ck, "TCP Chack", "Send Message Len :" & $Chk[0][1] & @CRLF & "Recv Message Len :" & $Chk[1][1])
TCPShutdown()

Func _TCPChack($msg, $port = 1024)
    Local $Ssock = TCPListen("127.0.0.1", $port)
    Local $Csock = TCPConnect("127.0.0.1", $port)
    Local $Asock = TCPAccept($Ssock)
    Local $Sendmsg = $msg
    
    TCPSend($Csock, $Sendmsg)

    Local $Recvmsg = TCPRecv($Asock, 1024)
    Local $Rtable[2][2]
    
    $Rtable[0][0] = $Sendmsg
    $Rtable[1][0] = $Recvmsg
    $Rtable[0][1] = StringLen($Sendmsg)
    $Rtable[1][1] = StringLen($Recvmsg)

    TCPCloseSocket($Ssock)
    TCPCloseSocket($Csock)
    TCPCloseSocket($Asock)
    
    Return $Rtable
EndFunc

..;

Edited by GreenBox

Share this post


Link to post
Share on other sites
BrettF
GreenBox

Hi,

Try sending as binary, then converting the string back... :)

Cheers,

Brett

But i only can 'TCPSend", not 'TCPRecv'..;

Share this post


Link to post
Share on other sites
BrettF
GreenBox

Try

TCPSent (ChrW (1234) & ChrW (3455)....) for sending the strings.

Cheers,

Brett

i can't it.

it is too hard.

#AutoIt3Wrapper_UseAnsi=n

$String = "안녕하세요? 이것은 테스트입니다." & @CRLF & "TEST 01234567890123456789"
$Str = ""

For $i = 1 to StringLen($String)
    $Str &= AscW(StringMid($String, $i, 1)) & '|'
Next

TCPStartup()
Local $Chk = _TCPChack($Str)
MsgBox(64, "Send Message", $Chk[0][0])
MsgBox(64, "Recv Message", $Chk[1][0])
If $Chk[0][1] = $Chk[1][1] Then
    Local $Ck = 64
Else
    Local $Ck = 16
EndIf
MsgBox($Ck, "TCP Chack", "Send Message Len :" & $Chk[0][1] & @CRLF & "Recv Message Len :" & $Chk[1][1])
TCPShutdown()

Func _TCPChack($msg, $port = 1024)
    Local $Ssock = TCPListen("127.0.0.1", $port)
    Local $Csock = TCPConnect("127.0.0.1", $port)
    Local $Asock = TCPAccept($Ssock)
    Local $Str = StringSplit($msg, "|")
    Local $Sendmsg, $i
    
    For $i = 1 to $Str[0]
        $Sendmsg &= ChrW($Str[$i])
        TCPSend($Csock, ChrW($Str[$i]))
    Next
    
    Local $Recvmsg = BinaryToString(TCPRecv($Asock, 1024))
    Local $Rtable[2][2]
    
    $Rtable[0][0] = $Sendmsg
    $Rtable[1][0] = $Recvmsg
    $Rtable[0][1] = StringLen($Sendmsg)
    $Rtable[1][1] = StringLen($Recvmsg)

    TCPCloseSocket($Ssock)
    TCPCloseSocket($Csock)
    TCPCloseSocket($Asock)
    
    Return $Rtable
EndFunc

if i recv it, recv msg broken...

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.