官网

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的更多相关文章

  1. php SqlServer 中文汉字乱码

    php SqlServer 中文汉字乱码,用iconv函数转换 查询显示的时候,从GB转换为UTF8 <?php echo iconv('GB2312','UTF-8',$row['Name'] ...

  2. linux 下vi /vim 中文汉字乱码解决

    http://my.oschina.net/laserdance/blog/53474很多win下编译的配置文件(译码格式有utf8/gbk)上传到linux服务器上时打开汉字乱码 解决方法如下: 修 ...

  3. 【转】CStdioFile UNICODE编译 英文系统下读取中文汉字乱码解决

    转载出处:http://www.cnblogs.com/ct0421/p/3242418.html 函数原形为:char *setlocale( int category, const char *l ...

  4. CStdioFile UNICODE编译 读取中文汉字乱码 .

    函数原形为:char *setlocale( int category, const char *locale );头文件:<locale.h>所支持的操作系统为:ANSI, Win 95 ...

  5. 关于 jsp java servlet 中文汉字乱码的解决方法

    在servlet类中的get,post最前面加上 req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding(&quo ...

  6. Oracle11g 创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题

    前提:本机已经安装了Oracle11g数据库. 需求:使用PL SQL数据库连接工具操作Oracle数据库 一.创建表空间和用户      想要操作数据库,首先需要创建用户并给用户授予权限:在创建用户 ...

  7. Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题

    [转载]原文地址:https://www.cnblogs.com/bjh1117/p/6605037.html 前提:本机已经安装了Oracle11g数据库. 需求:使用PL SQL数据库连接工具操作 ...

  8. 解决js输出汉字乱码问题

    当我们需要使用js输出汉字时,偶然会出现输出的中文汉字乱码的情况,在网上收了很多解决方案 1.在mata中加 <meta content="text/html; charset=utf ...

  9. Android项目,从web上取下汉字,中文部分乱码

    Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...

随机推荐

  1. makefile,让编译更简单

    陈皓 (CSDN) 概述—— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的 ...

  2. google play apk 下载

    https://apps.evozi.com/apk-downloader/?id=com.sgiggle.production

  3. 转 JavaScript中判断对象类型的种种方法

    我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一 ...

  4. [连载]Java程序设计(03)---任务驱动方式:寻找高富帅和屌丝

    版权声明:本文为博主原创文章,请在转载时说明出处. https://blog.csdn.net/jackfrued/article/details/26163877 任务:相同在上一家公司.公司还须要 ...

  5. dell support

    部門營業時間 電話號碼訂單支援中小型企業 (員工不多於 500名 )00852-3416-0910 9:00 - 18:00 訂單編號:  810607806 訂單日期:  26/11/2014 客戶 ...

  6. 【python】python性能分析--待完善

    http://www.oschina.net/translate/python-performance-analysis http://blog.csdn.net/gzlaiyonghao/artic ...

  7. ASP.NET 实现伪静态网页方法

    方法一:利用Httphandler实现URL重写(伪URL及伪静态) 我们有时候会见到这样的地址:“http://www.huoho.com/show-12-34.html”,你或许认为在站点服务器根 ...

  8. [转]Serv-U 配置

  9. 全局 SqlConnection

    class SqlHelper { public static SqlConnection conn; public static SqlConnection Open(string connStr) ...

  10. iframe引入百度地图显示企业位置

    步骤一:打开下面这个地址:http://api.map.baidu.com/lbsapi/creatmap/index.html     步骤二:定位中心点     在打开的页面左侧,输入企业的详细地 ...