找回密码
 加入
搜索
查看: 2986|回复: 14

UDPSend 要发送中文该如何处理?

[复制链接]
发表于 2008-9-8 05:59:04 | 显示全部楼层 |阅读模式
接收端要求输入的是UTF-8编码的中文.
我用StringToBinary 传递过去的中文老缺最后几个字
请教大虾了
发表于 2008-9-8 08:07:00 | 显示全部楼层
发表于 2008-9-8 09:06:34 | 显示全部楼层
#AutoIt3Wrapper_UseAnsi=y 就好了 使用 Ansi 编码
发表于 2009-1-20 09:55:20 | 显示全部楼层
晕啊,要用什么版本才可以?
发表于 2009-1-20 10:05:37 | 显示全部楼层
字符串》二进制》发送》接收》二进制转字符串
发表于 2009-1-20 10:41:10 | 显示全部楼层
测试过了,还是不行
===================
客户端

UDPStartup()

; Bind to a SOCKET
;==============================================
$socket = UDPBind(@IPAddress1, 65532)
If @error <> 0 Then Exit

While 1
    $data = UDPRecv($socket, 65532)
    If $data <> "" Then
        MsgBox(0, "接受到的信息", BinaryToString($data,4))
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

==================================
服务端

UDPStartup()
$test = StringToBinary("这个是虾米呀为什么不能显示完整的中文呢",4)

; Open a "SOCKET"
;==============================================
$socket = UDPOpen(@IPAddress1, 65532)
If @error <> 0 Then Exit

While 1
    Sleep(2000)
   
    $status = UDPSend($socket, $test)
    If $status = 0 then 
        MsgBox(0, "错误", "错误发送消息代码为: " & @error)
        Exit
    EndIf
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc
发表于 2009-1-20 11:22:10 | 显示全部楼层
S:
;;这是一个 UDP 服务器
;;Start this first

; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================
$socket = UDPBind("127.0.0.1", 65532)
If @error <> 0 Then Exit

While 1
    $data = UDPRecv($socket, 500,1)
    If $data <> "" Then
        MsgBox(0, "UDP 数据", BinaryToString($data,4), 1)
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc


C:
;;This is the UDP Client
;;Start the server first

; Start The UDP Services
;==============================================
UDPStartup()

; Open a "SOCKET"
;==============================================
$socket = UDPOpen("127.0.0.1", 65532)
If @error <> 0 Then Exit

$n=0
While 1
    Sleep(2000)
    $n = $n + 1
    $status = UDPSend($socket, StringToBinary("测试使用中文发送消息 #" & $n & '中文,english,1234567',4))
    If $status = 0 then 
        MsgBox(0, "错误", "当发送 UDP 消息时发生错误: " & @error)
        Exit
    EndIf
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc
发表于 2009-1-20 11:23:25 | 显示全部楼层
不是叫你加这句么...脚本里没看到你加啊

#AutoIt3Wrapper_UseAnsi=y
发表于 2009-1-20 11:24:18 | 显示全部楼层
我的代码运行正常
3.3.0.0.1 UNICODE
发表于 2009-1-20 11:36:08 | 显示全部楼层
解决了,不胜感激。
btw:我实在太菜了 lol
发表于 2009-1-20 11:37:42 | 显示全部楼层
原帖由 sxd 于 2009-1-20 11:23 发表
不是叫你加这句么...脚本里没看到你加啊

#AutoIt3Wrapper_UseAnsi=y

加了也无效,最新版。但从官网下载过N过旧版试过#AutoIt3Wrapper_UseAnsi=y无效,只能转换。
发表于 2009-1-20 12:37:49 | 显示全部楼层
原帖由 ceoguang 于 2009-1-20 11:37 发表

加了也无效,最新版。但从官网下载过N过旧版试过#AutoIt3Wrapper_UseAnsi=y无效,只能转换。



这是可以的,需要先编译。编译的就正常。直接运行现在调用的是UNICODE的。
发表于 2009-1-20 13:03:15 | 显示全部楼层
原来如此!!!
发表于 2009-1-20 21:27:48 | 显示全部楼层
学无止境。我是来学习的、
发表于 2017-6-3 07:20:54 | 显示全部楼层
UDPSend 要发送中文该如何处理?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-26 18:12 , Processed in 0.076498 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表