Closed Thread
Results 1 to 1 of 1

Thread: Delphi Sockets : Simple client and server program

  1. #1
    tosh5457's Avatar
    tosh5457 is offline Newbie
    Join Date
    May 2007
    Location
    Portugal
    Posts
    7
    Rep Power
    0

    Delphi Sockets : Simple client and server program

    Im gonna try to explain my problem:

    i got 2 exe's (Client and server).
    the client application sends strings to the server on button click and write the server response to a memo.
    the server application gets client strings and sends back a message saying "Recebido".
    When i start the client (with the server app already running) i get the message from server saying "Recebido", and when i send a message clicking the button the server sends the "Recebido" message. my problem is : when i send some string to the server again, the client doesnt write anything to the memo. i dunno if it is client or server's problem. here is the code of the client:

    Code:
    unit Cliente;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ScktComp;
    
    type
      TForm1 = class(TForm)
        Cliente: TClientSocket;
        Edit1: TEdit;
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure ClienteRead(Sender: TObject; Socket: TCustomWinSocket);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Cliente.Socket.SendText(Edit1.Text);
    end;
    
    procedure TForm1.ClienteRead(Sender: TObject; Socket: TCustomWinSocket);
    begin
      Memo1.Lines.Add(Socket.ReceiveText);
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Cliente.Open;
    end;
    
    end.
    and the server's:

    Code:
    unit Servidor;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ScktComp;
    
    type
      TForm1 = class(TForm)
        Servidor: TServerSocket;
        procedure ServidorClientRead(Sender: TObject; Socket: TCustomWinSocket);
        procedure FormCreate(Sender: TObject);
        procedure ServidorAccept(Sender: TObject; Socket: TCustomWinSocket);
    
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    procedure TForm1.ServidorClientRead(Sender: TObject;
      Socket: TCustomWinSocket);
    begin
      Servidor.Socket.Connections[0].SendText('Recebido');
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Servidor.Active := True;
    end;
    
    procedure TForm1.ServidorAccept(Sender: TObject; Socket: TCustomWinSocket);
    begin
       Servidor.Socket.Connections[0].SendText('Recebido');
    end;
    
    end.
    help me please
    Last edited by tosh5457; 05-26-2007 at 09:03 AM. Reason: didnt make myself clear

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sockets Server/Client ?
    By amw_drizz in forum C# Programming
    Replies: 1
    Last Post: 07-23-2011, 07:43 AM
  2. When to close sockets in a client server game
    By Metalhead in forum Java Help
    Replies: 2
    Last Post: 04-22-2011, 10:25 AM
  3. Replies: 7
    Last Post: 06-24-2010, 10:28 PM
  4. Help with C Client/Server Program (UDP Protocal)
    By handsomedan in forum C and C++
    Replies: 1
    Last Post: 03-24-2010, 11:04 AM
  5. Help with C Client/Server Program (UDP Protocal)
    By handsomedan in forum C and C++
    Replies: 0
    Last Post: 03-23-2010, 08:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts