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 ...
随机推荐
- RPC好,还是RESTful好?
看到知乎上有这样一个问题 WEB开发中,使用JSON-RPC好,还是RESTful API好? 还有其他优秀的推荐方案吗? -------------------------------------- ...
- java初始化块执行顺序
java中初始化块的执行顺序在构造器之前,多个初始化块之间定义在前的先执行.如下: public class InitialBlockTest { // The first one { System. ...
- C#获取本机IP地址(ipv4)
获取本机所有IP地址: 这些地址是包含所有网卡(虚拟网卡)的ipv4和ipv6地址. string name = Dns.GetHostName(); IPAddress[] ipadrlist = ...
- python 正则表达式的使用
本文以例子的形势,介绍如何在python中使用正则表达式. Example1 #!/usr/bin/python import re import sys pattern = re.compile(r ...
- oracle常用数据类型说明
类型 含义 存储描述 备注 CHAR 固定长度字符串 最大长度2000bytes VARCHAR2 可变长度的字符串, 最大长度4000bytes 可做索引的最大长度749 NCHAR 根据字符集而定 ...
- [转]触发窗体事件(例如按Esc关闭窗体),WinForm
设置窗体属性KeyPreview=True. private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Ke ...
- 对比两个表中,字段名不一样的SQL
需要包括有几种情况一.A表中有的字段B表无二.B表有的A表无三.两个表字段名不一致的 --------------------------------------------------------- ...
- SQL的datetime类型数据转换为字符串格式大全
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...
- redis在PHP中的基本使用案例(觉得比较实用)
源地址 http://www.t086.com/article/4901
- 小峰mybatis(4)mybatis使用注解配置sql映射器
主流开发还是使用xml来配置:使用注解配置比较快,但是不支持所有功能:有些功能还是得用配置文件: 一.基本映射语句: @Inert @Update @Delete @Select 二.结果集映射语句 ...