Article View: borland.public.cppbuilder.internet.socket
Article #1599Client code
From: Quentin David Jones
Date: Fri, 08 Dec 2006 01:09
Date: Fri, 08 Dec 2006 01:09
101 lines
4305 bytes
4305 bytes
Here is the main client code:
it inputs a filename from user,
sends it to the server,
displays the result :
//----------------------------------------------------------------------------
//Borland C++Builder
//Copyright (c) 1987, 1997-2002 Borland International Inc. All Rights Reserved.
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "mainClient.h"
//---------------------------------------------------------------------------
#pragma link "ScktComp"
#pragma resource "*.dfm"
TChatClientForm *ChatClientForm;
//---------------------------------------------------------------------------
__fastcall TChatClientForm::TChatClientForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::FileConnectItemClick(TObject *Sender)
{
// If client socket is active, then de-activate
if (ClientSocket->Active)
{
ClientSocket->Active = false;
}
// Get address to connect to
if (InputQuery("Computer to connect to", "Address Name:", Server))
{
// If server address entered
if (Server.Length() > 0)
{
// Set CLient host address, set client active
ClientSocket->Host = Server;
ClientSocket->Active = true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::Exit1Click(TObject *Sender)
{
// close all
ClientSocket->Close();
Close();
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::ClientSocketConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
// Client: connect - show status
StatusBar1->Panels->Items[0]->Text = "Connect to: " + Socket->RemoteHost;
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::Disconnect1Click(TObject *Sender)
{
// Disconnect - client off
ClientSocket->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::ClientSocketRead(TObject *Sender,
TCustomWinSocket *Socket)
{
// Client: Read - add input to memo
Memo2->Lines->Add(Socket->ReceiveText());
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::ClientSocketError(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
// Client: Error - display it
Memo2->Lines->Add("Error connecting to:" + Server);
ErrorCode = 0;
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::Edit1KeyPress(TObject *Sender, char &Key)
{
// When RETURN is pressed
if (Key == VK_RETURN)
{
// Send text to client socket
ClientSocket->Socket->SendText( Edit1->Text );
}
}
//---------------------------------------------------------------------------
void __fastcall TChatClientForm::FormCreate(TObject *Sender)
{
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<4578bb23@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4578ba1b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c2ba0c1ed7538b68 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Quentin David Jones" <quentin.jones@romteck.com.spamprotect> Newsgroups: borland.public.cppbuilder.internet.socket References: <4578ba1b@newsgroups.borland.com> Subject: Client code Date: Fri, 8 Dec 2006 10:09:40 +0900 Lines: 103 Organization: Romteck P/L X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 203.59.8.178 Message-ID: <4578bb23@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1165540131 203.59.8.178 (7 Dec 2006 17:08:51 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail