i have to programs that i'm trying to send text over network client side:
eXen(TheCoder)
unit fathimessclient;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Edipserver: TEdit;
Label1: TLabel;
Btconnect: TButton;
Btdisconnect: TButton;
Edmsg: TEdit;
Label2: TLabel;
btsend: TButton;
ClientSck: TClientSocket;
Button1: TButton;
OpenDialog1: TOpenDialog;
Edfile: TEdit;
Label3: TLabel;
btfile: TButton;
BtShow: TButton;
show: TMemo;
procedure BtconnectClick(Sender: TObject);
procedure BtdisconnectClick(Sender: TObject);
procedure btsendClick(Sender: TObject);
procedure ClientSckConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure ClientSckError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure btfileClick(Sender: TObject);
procedure BtShowClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.BtconnectClick(Sender: TObject);
begin
if not clientsck.Active then
Clientsck.Address:=Edipserver.Text;
Clientsck.Active:=true;
end;
procedure TForm1.BtdisconnectClick(Sender: TObject);
begin
if clientsck.Active then
clientsck.Active:=false;
self.caption:='Disconnecting..';
end;
procedure TForm1.btsendClick(Sender: TObject);
begin
clientsck.Socket.SendText(edmsg.Text);
end;
procedure TForm1.ClientSckConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
caption:='connecting in progress'
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
edfile.Te xt:=OpenDialog1.FileName;
end;
procedure TForm1.ClientSckError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
procedure TForm1.btfileClick(Sender: TObject);
var Fil:TFileStream;
begin
if edfile.Text='' then
CreateMessageDialog('You must Specify file name',mtError,mbyesnocancel)
//ShowMessage(' You must Specify file name ')
else
Fil:=TFileStream.Create(OpenDialog1.FileName,fmCreate);
(E.Message,E.Helpcontext);
end;
procedure TForm1.BtShowClick(Sender: TObject);
begin
show.Show;
if edfile.Text='' then
begin
self.show.Hide;
ShowMessage(' No File exit to view Please type file name ');
end
else
show.Lines.LoadFromFile(edfile.Text);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.show.Hide;
end;
end.
server side :
unit ServerSide;
interface
uses
Windows, Messages, Sys Utils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
btListen: TButton;
btClose: TButton;
ServerSct: TServerSocket;
meout: TMemo;
edMess: TEdit;
btSend: TButton;
procedure btListenClick(Sender: TObject);
procedure btCloseClick(Sender: TObject);
procedure ServerSctListen(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerSctClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSctClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSctClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerSctAccept(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerSctClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure btSendClick(Sender: TObject);
private< br> { Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btListenClick(Sender: TObject);
begin
if not ServerSct.Active then
ServerSct.Active :=true;
end;
procedure TForm1.btCloseClick(Sender: TObject);
begin
if not ServerSct.Active then
ServerSct.Active:=true;
self.Caption:='server closing ';
end;
procedure TForm1.ServerSctListen(Sender: TObject;
Socket: TCustomWinSocket);
begin
caption:='Listening...';
end;
procedure TForm1.ServerSctClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
meOut.Lines.add('Connecting : '+ Socket.RemoteAddress);
end;
procedure TForm1.ServerSctClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
meOut.Lines.add('DisConnected:'+socket.RemoteAddress);
end;
procedure TForm1.ServerSctClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TEr rorEvent;
var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
procedure TForm1.ServerSctAccept(Sender: TObject;
Socket: TCustomWinSocket);
begin
caption:= 'client is accepted';
end;
procedure TForm1.ServerSctClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
meOut.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.btSendClick(Sender: TObject);
var i:integer;
begin
for i:=0 to serversct.Socket.ActiveConnections do
serversct.Socket.Connections[i].SendText(edMess.text);
end;
end.