IdUDPServer中文汉字乱码 及IdTCPClient
官网
http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdTCPServer_OnExecute.html
IdUDPServer1中文汉字乱码,用IndyTextEncoding_OSDefault字符编码就解决问题了
IdUDPServer1.Send(1.1.1.1,8080,'中国人',IndyTextEncoding_OSDefault);
发送字节
IdUDPServer1.SendBuffer(const System::UnicodeString AHost, const System::Word APort, const Idglobal::TIdBytes ABuffer);
TIdBytes 就是TBytes就是TByteDynArray
udp bytes byte
procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
lastMsg := BytesToString(AData, IndyTextEncoding_OSDefault);
end;
TCP,IdTCPClient
IndyTextEncoding
IdTCPClient1.IOHandler.WriteLn(sendData,IndyTextEncoding(TEncoding.ANSI));
发送中文如果是乱码请用这种方法编码修改就可以了,ansi、 utf8等看对方的要求编码格式了。
bs:TBytes;
setlength(bs,8);
IdTCPClient1.IOHandler.Write(TIdBytes(bs));
c++
String rstr = BytesToString(AData, IndyTextEncoding_UTF8());
https://stackoverflow.com/questions/13839094/how-to-read-all-bytes-from-server-using-indy-client-in-delphi
https://forums.embarcadero.com/thread.jspa?threadID=211952
IdTCPClient1->Host =GStack->LocalAddress;;
IdTCPClient1->Port = 9080;
IdTCPClient1->Connect();
TCP发送buff
TFileStream *fs;
String FilePath=”c:\\test.data";
fs = new TFileStream(fileNamePath, fmOpenRead);
IdTCPClient1->IOHandler->WriteBufferOpen();
IdTCPClient1->IOHandler->WriteLn(fileName);
IdTCPClient1->IOHandler->Write(fs,false,True);
delete fs;
IdTCPClient1->IOHandler->WriteBufferClose();
TCP接收buff
void __fastcall TFrmServer::IdTCPServer1Execute(TIdContext *AContext)
{
TFileStream *fs;
try
{
FileName = AContext->Connection->IOHandler->ReadLn("",);
}
catch(...)
{
return;
} if( FileName.IsEmpty() )
return;
FileNew = DataFilePath + FileName;
fs = new TFileStream(FileNew, fmCreate); AContext->Connection->IOHandler->ReadStream (fs,-,false);
delete fs;
//新版没有这个线程函数了
//AContext->Connection->Synchronize(frmksjg->BitBtn1->Click);
}
https://stackoverflow.com/questions/10361446/delphi-indy-10-demo-application-client-server
https://stackoverflow.com/questions/25438309/indy10-idtcpclients-iohandler-send-additional-data
https://stackoverflow.com/questions/25438309/indy10-idtcpclients-iohandler-send-additional-data
https://forums.embarcadero.com/thread.jspa?threadID=115603
// 在线程中
// while(!Terminated && MainForm->IdTCPClient1->Connected())
{
IdTCPClient1->Socket->CheckForDataOnSource(100);
if (IdTCPClient1->Socket->InputBufferIsEmpty() == false)
{
int nReceive = IdTCPClient1->Socket->InputBuffer->Size;
char Buf[10240];
// nReceive = Min(nReceive, sizeof(Buf));
TIdBytes tmp;
IdTCPClient1->Socket->ReadBytes(tmp, nReceive); // 读数据
BytesToRaw(tmp, Buf, nReceive);
// MainForm->fsUpdateFile->Write(Buf, nReceive); //写入文件
}
}
看客户发完等待接收
Sleep();
idbuf:TIdBytes;
while True do
begin
tcpClient1.IOHandler.CheckForDataOnSource();
if tcpClient1.IOHandler.InputBuffer.Size > then begin
SetLength(barray, tcpClient1.IOHandler.InputBuffer.Size);
tcpClient1.IOHandler.ReadBytes( idbuf, tcpClient1.IOHandler.InputBuffer.Size,false);
sret := tencoding.Default.GetString(idbuf);
break;
end; end;
c++
TBytes bv; IdTCPClient1->IOHandler->CheckForDataOnSource();
if (!IdTCPClient1->IOHandler->InputBufferIsEmpty())
{
int nReceive = IdTCPClient1->IOHandler->InputBuffer->Size;
bv.set_length();
bv.set_length(nReceive);
IdTCPClient1->IOHandler->ReadBytes(bv, nReceive, false);
sret = TEncoding::Default->GetString(bv);
}
IdUDPServer中文汉字乱码 及IdTCPClient的更多相关文章
- php SqlServer 中文汉字乱码
php SqlServer 中文汉字乱码,用iconv函数转换 查询显示的时候,从GB转换为UTF8 <?php echo iconv('GB2312','UTF-8',$row['Name'] ...
- linux 下vi /vim 中文汉字乱码解决
http://my.oschina.net/laserdance/blog/53474很多win下编译的配置文件(译码格式有utf8/gbk)上传到linux服务器上时打开汉字乱码 解决方法如下: 修 ...
- 【转】CStdioFile UNICODE编译 英文系统下读取中文汉字乱码解决
转载出处:http://www.cnblogs.com/ct0421/p/3242418.html 函数原形为:char *setlocale( int category, const char *l ...
- CStdioFile UNICODE编译 读取中文汉字乱码 .
函数原形为:char *setlocale( int category, const char *locale );头文件:<locale.h>所支持的操作系统为:ANSI, Win 95 ...
- 关于 jsp java servlet 中文汉字乱码的解决方法
在servlet类中的get,post最前面加上 req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding(&quo ...
- Oracle11g 创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
前提:本机已经安装了Oracle11g数据库. 需求:使用PL SQL数据库连接工具操作Oracle数据库 一.创建表空间和用户 想要操作数据库,首先需要创建用户并给用户授予权限:在创建用户 ...
- Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
[转载]原文地址:https://www.cnblogs.com/bjh1117/p/6605037.html 前提:本机已经安装了Oracle11g数据库. 需求:使用PL SQL数据库连接工具操作 ...
- 解决js输出汉字乱码问题
当我们需要使用js输出汉字时,偶然会出现输出的中文汉字乱码的情况,在网上收了很多解决方案 1.在mata中加 <meta content="text/html; charset=utf ...
- Android项目,从web上取下汉字,中文部分乱码
Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...
随机推荐
- jquery的常用操作(操作html页面的Dom对象的元素)
一:页面加载完成时,会执行jquery的方法(不需要等待图片加载完成,只要dom结构加载完成,就执行该方法) //第一种写法: $(document).ready(function() { // 执行 ...
- goss 简单快捷的服务器测试检验工具
goss 是一个简单.快捷的服务器测试检验工具,dgoss 是一个包装可以支持基于容器的开发模式 同时可以暴露测试结果为一个http endpoint,比较方便. 使用goss容器运行 使用数据卷的模 ...
- xml时间配置
这些星号由左到右按顺序代表 : * * * * * * * 秒 分 时 日 月 周 年 序号 说明 是否必填 允许填写的值 允许的通配符 秒 是 0-59 , - * / 分 是 0-59 , - * ...
- hadoop框架结构介绍
近年,随着互联网的发展特别是移动互联网的发展,数据的增长呈现出一种爆炸式的成长势头.单是谷歌的爬虫程序每天下载的网页超过1亿个(2000年数据,)数据的爆炸式增长直接推动了海量数据处理技术的发展.谷歌 ...
- xml表头内容什么意思
我来给你解释一下吧,首先这个文件是一个xml文件,那么他里面的所有内容都符合xml语法规范,开头的<project></project>这最外层同样也是一个xml文件的标签,后 ...
- JZ2440 裸机驱动 第13章 LCD控制器(1)
本章目标 了解LCD显示器的接口及时序: 掌握S3C2410/S3C2440 LCD控制器的使用方法: 了解帧缓冲区的概念,掌握如何设置帧缓冲区来显示图像: 13.1 LCD和LCD控制器 13.1 ...
- bzoj4271: chemistry 化学
给定点数n<=500,无标号,度<=4,无根树计数 预处理 无标号,孩子数<=3的有根树个数g 无标号,含k棵树,孩子数<=3的有根树森林个数s[k] 考虑大小为n的无根树的重 ...
- COMMON INTERVIEW QUESTIONS
1. What do you see yourself doing five years from now? 2. What motivates you to put forth your great ...
- zclip复制到剪切板插件有个bug
今天发现zclip复制到剪切板插件有个bug,就是在遨游和360浏览器的兼容模式下,点击复制没响应,后来我看了页面代码,发现在这两个浏览器的兼容模式下,生成的是<object>,其他浏览器 ...
- 跨域获取json数据
原文地址:http://my.oschina.net/LinBandit/blog/34570 前阵子做了一个前端动态加载json数据的应用,其中使用xmlhttprequest动态加载js,但是 ...