送分问题在线等,winsock传送字符收到乱码,怎么样解决?(50分)

  • 主题发起人 主题发起人 塬上独狼
  • 开始时间 开始时间

塬上独狼

Unregistered / Unconfirmed
GUEST, unregistred user!
unit cs;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls,winsock, MSWinsockLib_TLB;

type
TForm1 = class(TForm)
Winsock1: TWinsock;
Label1: TLabel;
Label2: TLabel;
memo1: TMemo;
memo2: TMemo;
procedure FormCreate(Sender: TObject);
procedure memo1Change(Sender: TObject);
procedure Winsock1DataArrival(ASender: TObject; bytesTotal: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
winsock1.LocalPort :=1998;
winsock1.RemoteHost :='11.12.18.5';
winsock1.RemotePort:=1998;
end;

procedure TForm1.memo1Change(Sender: TObject);
begin
winsock1.SendData(memo1.Text );
end;

procedure TForm1.Winsock1DataArrival(ASender: TObject;
bytesTotal: Integer);
var
lr:olevariant;
begin
winsock1.GetData(lr) ;
memo2.Text :=lr;
end;

end.
 
TWinsock 还真没有用过.不过感觉出现问题的原因是发送和接收应该指定长度的.
 
TWinsock我也没用过.都是用Indy或winsock来发的.它们在发送和接收的时候.都要指定发送或接收的缓冲区的大小.
 

Similar threads

I
回复
0
查看
524
import
I
I
回复
0
查看
625
import
I
后退
顶部