Article View: borland.public.cppbuilder.internet.socket
Article #1602Server as application - works fine
From: Quentin David Jones
Date: Fri, 08 Dec 2006 01:12
Date: Fri, 08 Dec 2006 01:12
62 lines
2856 bytes
2856 bytes
Here is the Server as Application:
It accepts a filename, returns the file/date
Works fine with client above.
//----------------------------------------------------------------------------
//Borland C++Builder
//Copyright (c) 1987, 1997-2002 Borland International Inc. All Rights Reserved.
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Srvmain.h"
//---------------------------------------------------------------------------
#pragma link "ScktComp"
#pragma resource "*.dfm"
TChatSrvForm *ChatSrvForm;
//---------------------------------------------------------------------------
__fastcall TChatSrvForm::TChatSrvForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TChatSrvForm::FormCreate(TObject *Sender)
{
// When task is created - start listening
ServerSocket->Active = true;
}
//---------------------------------------------------------------------------
void __fastcall TChatSrvForm::ServerSocketClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
// File name and age
AnsiString FileName, FileResult;
TDateTime FileDateTime;
int Age;
// copy filename from client
FileName = Socket->ReceiveText();
// Lookup file length
Age = FileAge( FileName );
if( Age == -1 )
{
// File Not found
FileResult = "File Not Found";
}
else
{
// File found - return date/time
FileDateTime = FileDateToDateTime( Age );
FileResult = FileName + " date: " + (AnsiString) FileDateTime;
}
// Now return the result to the client
ServerSocket->Socket->Connections[0]->SendText( FileResult );
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<4578bbc0@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!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: Server as application - works fine Date: Fri, 8 Dec 2006 10:12:17 +0900 Lines: 65 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: <4578bbc0@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1165540288 203.59.8.178 (7 Dec 2006 17:11:28 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail