请问一对socket之间可以既用来传送数组又来传送文本吗,若行,对端怎样识别?
解决方案 »
- mscomm控件奇怪问题,请高手进来指点.在线等(40分)
- 求一个统计类的SQL语句,想了好半天没有答案了
- Win9x下DELPHI代码编码问题?急急急
- 一个曾经对软件狂热的程序员,想转行开个小店,真诚转让我自己独立开发的产品,寻找买主
- Delphi打包问题:肯定给分
- 关于调用查询的存储过程出现的问题 急~
- delphi6里面是不是没有midaspageproducer控件??
- 答谢各位了,关于“ 斑竹求救,过路朋友看看“ 给分贴,凡是回答过问题的来接分
- 学了一辈子的Delphi,居然连最基本的Windows程序结构也不懂
- DELPHI方面的木马程序资料
- ADO TABLE 中的DATAFIELD 的验证
- 各位GG帮帮我好吗,我毕业设计有点问题!
可以把数组或文本用一个结构体封装,
再把整个结构体发送,根据标志判断是文本还是数组
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
type myrecord = record
Flag:Integer;
Text:String;
myArray:array[0..10] of Integer;
end;
type
TForm1 = class(TForm)
ServerSocket: TServerSocket;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
CheckBox1: TCheckBox;
ClientSocket: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var Command:myrecord;
begin
if CheckBox1.Checked then
begin
command.Flag := 0;
command.Text := 'This is Text';
end
else
begin
command.Flag := 1;
//初始化数组 end;
ClientSocket.Socket.SendBuf(Command,SIZEOF(Command));
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ServerSocket.Active := true;
ClientSocket.Active := true;
end;procedure TForm1.ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var rec:myrecord;
i: integer;
begin
Socket.ReceiveBuf(rec,Socket.ReceiveLength);
if rec.Flag = 0 then
Edit2.Text := rec.Text
else
begin
for i := Low(rec.myArray) to High(rec.myArray) do
ComboBox1.Items.Add(IntToStr(rec.myarray[i]))
end;
end;end.