Solved

delphi3 tcp

Posted on 1998-03-16
1
314 Views
Last Modified: 2011-09-20
I'm programming a client/server program and using the delphi3's component TCP. I can't get them connected. I'm being forcefully rejected. I need a example of a chat program that use this component. or somthing like that.
0
Comment
Question by:mayta8
1 Comment
 
LVL 3

Accepted Solution

by:
williams2 earned 60 total points
ID: 1360516
Yes, I know exactly what you have to do:

1. The TCP component is an OCX, and DELPHI includes a "isp3" in the USES clause. BUT!!! Delphi "forgets" to include ACTIVEX. Insert it manually after drawing the component to the Form.

When creating an instance of TTCP in the FORM (What you may have to) each and every client, DO remember to set it's .PARENT property (EX. TCP1.Parent:= Self), else there won't be generated any events.

Here's some examples:

Procedure ConnectButtonClick(Sender: TObject);
var
  RemoteIP: String;
Begin
  RemoteIP:= '10.0.0.7';
  TCP1.Connect(RemoteIP,TCP1.LocalPort);
End;

Procedure SendButton1Click(Sender: TObject);
var
  Data: OleVariant;
Begin
  Data:= Edit1.Text; //Edit field
  // When using ARRAYS remember to lookup TSafeArray!!!
  // OleVariants can hold almost anything.
  TCP1.SendData(Data); //
End;

procedure TForm1.TCP1ConnectionRequest(Sender: TObject;
  requestID: Integer);
begin
  //TCP1 was in listen-mode, when generating this event
  TCP2.Accept(requestID); //You need to hand the requestID to another instance of TTCP!
  ShowMessage('Request received from '+TCP1.RemoteHostIP);
  TCP1.Close;
  TCP1.Listen;
end;

procedure TForm1.TCP2DataArrival(Sender: TObject; bytesTotal: Integer);
var
  Data: OleVariant;
Begin
  TCP2.GetData(Data, VT_BSTR,BytesTotal);
  Memo1.Lines.Add(Data);
end;

procedure ResetButtonClick(Sender: TObject);
Begin
  TCP1.Close;
  TCP2.Close;
  TCP1.Listen;
End;

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question