Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Apr : idtcpserver\client chat app

www.cryer.info
Managed Newsgroup Archive

idtcpserver\client chat app

Subject:idtcpserver\client chat app
Posted by:"Keith" (..@hotmail.com)
Date:25 Apr 2005 17:55:19

I've just moved from VB where i used Winsock6 to easily create chat applications. I've now started using Delphi7 and run into trouble trying to create a chat app with indy10.0.52.

On the server side, i do not know how to keep listening for message coming from the client(without the server freezing!), what method is used for that? A timer perhaps? Also, in VB, the server can send messages back to client, is this possible with idtcpserver? and how can that be done? basically, i need some example of how to send and recieve  messages with the server.

On the clientside, how do i send and recieve messages? When i send more than one message, only the first msg is displayed by the server, i dont know what happens to the rest.
Also, how do i creaete a custom error msg, when a client connects and finds that a server is not listening at a set port? I would prefer to have a custom error msg, instead of the exception errormsg that comes up when the above situation occurs.
Below is an outline of the code i managed to put together:

client code
procedure TForm1.FormCreate(Sender: TObject);
begin
tc.Host:=edip.Text;
tc.Port:=strtoint(edport.Text);
end;

procedure TForm1.btConnectClick(Sender: TObject);
begin
with tc do
begin
try
      Connect;
      msg.Lines.Add(tc.IOHandler.ReadLn);
      except on E : Exception do
         ShowMessage('Oh no!!');
      end;
      end;

end;

procedure TForm1.btsendClick(Sender: TObject);
begin
tc.IOHandler.WriteLn('Client: ' +edmsg.Text);
msg.lines.add(tc.IOHandler.ReadLn);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
tc.Destroy;
end;

procedure TForm1.btexitClick(Sender: TObject);
begin
close;
end;

Server code:
procedure TForm1.FormCreate(Sender: TObject);
begin
ts.DefaultPort:=strtoint(edport.Text);
end;

procedure TForm1.btconnectClick(Sender: TObject);
begin
ts.Active:=true;
memo1.Lines.Add('connected');
end;

procedure TForm1.tsConnect(AContext: TIdContext);
begin
acontext.Connection.IOHandler.WriteLn('Hello babe!');
memo1.Lines.Add(acontext.Connection.Socket.ReadLn);
end;

procedure TForm1.tsExecute(AContext: TIdContext);
begin
acontext.Connection.IOHandler.WriteLn('DONT KNOW WHAT TO DO HERE');
end;
tHANKS

  

Replies:

www.cryer.info
Managed Newsgroup Archive