![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
||||
|
||||
|
сервер
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
TcpServer1: TTcpServer;
procedure TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
stream: TMemoryStream;
msg: string;
sz: integer;
begin
if ClientSocket.Connect then
begin
msg := ClientSocket.Receiveln;
stream := TMemoryStream.Create;
sz := StrToInt(msg);
stream.SetSize(sz);
ClientSocket.Sendln('ok');
ClientSocket.ReceiveBuf(stream.Memory^, sz);
stream.SaveToFile('otchet.txt');
stream.Free;
end;
ClientSocket.Disconnect;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TcpServer1.LocalHost:=edit1.Text;
TcpServer1.Open;
end;
end.клиент Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Sockets;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
TcpClient1: TTcpClient;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
stream: TMemoryStream;
msg: string;
begin
tcpClient1.Remotehost:=edit1.Text;
tcpClient1.Active := true;
if TcpClient1.Connect then
begin
stream := TMemoryStream.Create;
stream.LoadFromFile('otchet.txt');
TcpClient1.Sendln(IntToStr(stream.Size));
if TcpClient1.Receiveln = 'ok' then
TcpClient1.SendBuf(stream.Memory^, stream.Size);
tcpClient1.Active := false;
TcpClient1.Disconnect;
end
else showmessage('Error connecting');
end;
end.локально на одном пк все работает если ставить 127.0.0.1 а вот по инету уже не работает, не работает и тогда если у сервера 127.0.0.1 а у клиента, что запускаю на этом же пк, мой айпи. срабатывает showmessage('Error connecting'); в чем дело вот? Цитата:
|