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 ...
随机推荐
- echar生成雷达图
function createRadarChart(indicatorData, personData) { var myChart = echarts.init(document.getElemen ...
- java企业级开发的实质就是前台后台如何交互的-各个对象之间如何交互,通信的-程序执行的流程是怎样的
1.开山鼻祖-servlet 如何将url 和 strvlet(.java文件)联系起来的 顺平说的:在xml中,url先找到xml,由对应的url的得到servlet那个类,然后就可以输入一个网址访 ...
- ansible copy file
ansible xxxip -m copy -a 'src=/localdir/file dest=/sss/xxx/basic_search/bin/'
- hive 创建orc表
orc表 创建具备ACID及Transactions的表 这里的表需要具备下面几个条件: 1. 必须以 ORC 格式存储 2. 必须分 bucket,且不能 sort 3. 必须显式声明tran ...
- pipelinedb continuous view 操作
continuous view 是 pipelinedb的核心,类似一个view,但是数据是合并了stream以及table的数据输入数据,并且是 实时根据输入数据进行更新的 语法 CREATE CO ...
- sql server 数字字符串的排序
假如我们有这样的数据格式1#XXXXX 20#CCCCC等的一系列数据那么我们如何可以排序出1 ,2,3,4,5,6,7.......这样的数据呢 我们知道整数是可以排序成这样的格式的,但是字符串就不 ...
- mybatis 生成 映射文件生成工具 mybatisGenerator 使用
第一:新建 generatorConfig.xml 文件 ,写入下面的 内容 <?xml version="1.0" encoding="UTF-8"?& ...
- IE版本检测
<html><body><script type="text/javascript">var browser=navigator.appName ...
- python2.7中出现TypeError: must be type, not classobj
class Person: def __init__(self,name,age): self._name = name self._age = age class Student(Person): ...
- Kong管理UI -kong-dashboard (附kong封装webservice方法)
本文仍然是在centos 6.7的环境下进行 本文转载请注明出处 —— xiaoEight btw如果要正常使用管理UI,前提为kong已经正常run(可参考)起来,此 ...