Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Sockets Connecting

[b][red]This message was edited by Smokedice at 2004-1-26 13:55:58[/red][/b][hr]
Can anyone guide me to a tutorial or know how to program sockets in delphi. Please can i have some help, i would be most grateful

cheers mark

Comments

  • cycordcycord Member Posts: 148
    : [b][red]This message was edited by Smokedice at 2004-1-26 13:55:58[/red][/b][hr]
    : Can anyone guide me to a tutorial or know how to program sockets in delphi. Please can i have some help, i would be most grateful
    :
    : cheers mark
    :
    try help on what component you want, i have started there
  • cycordcycord Member Posts: 148
    heres a sample code // Client Program:
    // Send 'power' to Client to shutdown the machine.
    // Send 'reset' to Client to reset the machine.

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,

    Forms,
    Dialogs, StdCtrls, ComCtrls, ScktComp;

    type
    TForm1 = class(TForm)
    Clientsocket1: TClientSocket;
    StatusBar1: TStatusBar;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Button3: TButton;
    CheckBox1: TCheckBox;
    Checkbox2: TCheckBox;
    procedure Button1Click(Sender : TObject);
    procedure Button2Click(Sender : TObject);
    procedure Clientsocket1Error(Sender : TObject; Socket :

    TCustomWinSocket;
    ErrorEvent : TErrorEvent; var ErrorCode : integer);
    procedure Clientsocket1Disconnect(Sender : TObject;
    Socket : TCustomWinSocket);
    procedure Clientsocket1Connect(Sender : TObject;
    Socket : TCustomWinSocket);
    procedure Button3Click(Sender : TObject);
    procedure FormClose(Sender : TObject; var Action : TCloseAction);
    procedure FormDestroy(Sender : TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1 : TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender : TObject);
    begin
    Clientsocket1.Active := True;
    end;

    procedure TForm1.Button2Click(Sender : TObject);
    begin
    Clientsocket1.Active := False;
    end;

    procedure TForm1.Clientsocket1Error(Sender : TObject;
    Socket : TCustomWinSocket; ErrorEvent : TErrorEvent;
    var ErrorCode : integer);
    begin
    errorcode := 0;
    StatusBar1.SimpleText := 'Error';
    end;

    procedure TForm1.Clientsocket1Disconnect(Sender : TObject;
    Socket : TCustomWinSocket);
    begin
    StatusBar1.SimpleText := 'Disconnect';
    end;

    procedure TForm1.Clientsocket1Connect(Sender : TObject;
    Socket : TCustomWinSocket);
    begin
    StatusBar1.SimpleText := Clientsocket1.Address;
    end;

    procedure TForm1.Button3Click(Sender : TObject);
    var
    ukaz : string;
    orders : string;
    Text : string;
    box : string;
    begin
    ukaz := edit1.Text;
    Clientsocket1.Socket.SendText(ukaz);
    if checkbox1.Checked = True then
    begin
    orders := 'power';
    Clientsocket1.Socket.SendText(orders);
    end;
    if Checkbox2.Checked = True then
    begin
    Text := 'reset';
    Clientsocket1.Socket.SendText(Text);
    end;
    end;

    procedure TForm1.FormClose(Sender : TObject; var Action :

    TCloseAction);
    begin
    Clientsocket1.Active := False;
    end;

    procedure TForm1.FormDestroy(Sender : TObject);
    begin
    Clientsocket1.Active := False;
    end;

    end.


    // Client Program

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,

    Forms,
    Dialogs, ScktComp, StdCtrls, ShellApi;

    type
    TForm1 = class(TForm)
    Label1: TLabel;
    Serversocket1: TServerSocket;
    procedure FormClose(Sender : TObject; var Action : TCloseAction);
    procedure FormDestroy(Sender : TObject);
    procedure FormCreate(Sender : TObject);
    procedure Serversocket1ClientError(Sender : TObject;
    Socket : TCustomWinSocket; ErrorEvent : TErrorEvent;
    var ErrorCode : integer);
    procedure Serversocket1ClientRead(Sender : TObject;
    Socket : TCustomWinSocket);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1 : TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.FormClose(Sender : TObject; var Action :

    TCloseAction);
    begin
    Serversocket1.Active := False;
    end;

  • SmokediceSmokedice Member Posts: 38
    Wow your a god send, iv been lookin all over the internet for some simple code like that.

    Thanks alot mark
Sign In or Register to comment.