Solved

delphi3 tcp

Posted on 1998-03-16
1
312 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now