🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
27 messages
27 total messages Started by Quentin David Jones Fri, 08 Dec 2006 01:05
Socket Service not responding? Code follows
#1597
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:05
34 lines
1927 bytes
Greetings all,

Well, I am stuck with my socket service.
Here is how I proceeded:
1. Built a simple Chat Server and separate Chat Client based on Borland's internet chat example - that worked fine.
2. Changed the Client to send a filename and the Server to return the file date - that worked.
3. Strip all UI elements from the server - that worked

Finally -
4. Convert the Server to a service, using code from the Borland service examples.

The result of step 4 :
* I can install, uninstall, and start, stop the service correctlly
* But the service does not respond to the client

I am unsure about the ServiceExecute function - currently I have a loop like so:
<code starts>
    while( !Terminated )
      ServiceThread->ProcessRequests(true);
<code ends>
I suspect that is not right?

So,
I will post the code below in 3 sections :
* Client
* Server application (works)
* Server service (does not respond)

I dare say it's a simple problem - at least to experts, if not to me :-)

regards


Quentin
Re: Socket Service not responding? Code follows
#1598
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 01:07
24 lines
1689 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578ba1b@newsgroups.borland.com...

> The result of step 4 :
> * I can install, uninstall, and start, stop the service correctlly
> * But the service does not respond to the client

Then you did something wrong.  Sockets work fine in services.  Please show
your actual service code.

> I am unsure about the ServiceExecute function - currently I have a loop
like so:
> <code starts>
>     while( !Terminated )
>       ServiceThread->ProcessRequests(true);
> <code ends>
> I suspect that is not right?

Get rid of the OnExecute event handler altogether.  You don't need it.
TService manages SCM requests just fine without it.


Gambit
Client code
#1599
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:09
101 lines
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)
{

}
//---------------------------------------------------------------------------
Server as application - works fine
#1602
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:12
62 lines
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 );
}
//---------------------------------------------------------------------------
Server as Service - not working
#1600
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:15
135 lines
4759 bytes
Finally, here is the Server as a service.
This version does not work.
I suspect the inner loop in ServiceExecute.


//---------------------------------------------------------------------------
#include "DateSvc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TFileDateService *FileDateService;
//---------------------------------------------------------------------------

__fastcall TFileDateService::TFileDateService(TComponent* Owner)
 : TService(Owner)
{
}

TServiceController __fastcall TFileDateService::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
 FileDateService->Controller(CtrlCode);
}

//---------------------------------------------------------------------------
// Service Execute - mainline of service

void __fastcall TFileDateService::ServiceExecute(TService *Sender)
{
  // Handle exceptions
  try
  {
    // Enable the socket
    ServerSocket->Active = true;
    ShowMessage("Socket activated");

    // handle requests until service terminated
    while( !Terminated )
    {
      // Not sure if this is right - QQQ
      ServiceThread->ProcessRequests(true);
    }

    // disable socket and exit
    ServerSocket->Active = false;
    ShowMessage("Socket de-activated");
  }
  catch(...)
  {
    // Not implemented yet - QQQ
    ShowMessage("d'oh");
  }
}

//---------------------------------------------------------------------------
// ServerSocketClientRead - called when data available for reading from client

void __fastcall TFileDateService::ServerSocketClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
  // File name and age variables
  AnsiString FileName, FileResult;
  TDateTime FileDateTime;
  int Age;

  ShowMessage("ClientRead");

  // handle exceptions
  try
  {
    // copy filename from client
    FileName = Socket->ReceiveText();

    // Lookup file date
    Age = FileAge( FileName );
    if( Age == -1 )
    {
      // File Not found
      FileResult = FileName + " : 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 );
  }
  catch(...)
  {
    // Not implemented yet - QQQ
    ShowMessage("D'oh !");
  }
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServiceStart(TService *Sender,
      bool &Started)
{
   Started = true;
   ServiceRunning = true;
   ShowMessage("Date Svc Started");
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStop(TService *Sender, bool &Stopped)
{
   Stopped = true;
   ServiceRunning = false;
   ShowMessage("Date Svc Stopped");
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServicePause(TService *Sender, bool &Paused)
{
   Paused = true;
   ServiceRunning = false;
   ShowMessage("Date Svc Paused");
}
//---------------------------------------------------------------------------

void __fastcall TFileDateService::ServiceContinue(TService *Sender,
      bool &Continued)
{
   Continued = true;
   ServiceRunning = true;
   ShowMessage("Date Svc Continued");
}
//---------------------------------------------------------------------------
OnExecute - will remove
#1601
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:18
21 lines
1550 bytes
Greetings,

Thanks for your reply :-)


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4578baa6$1@newsgroups.borland.com...
> Then you did something wrong.  Sockets work fine in services.  Please show
> your actual service code.

Well, of course I did.
That's why I am here asking experts like you for help :-)


> Get rid of the OnExecute event handler altogether.  You don't need it.
> TService manages SCM requests just fine without it.

Roger,
will try that.


Q.
Re: Removed ServiceExecute - now user account issues?
#1603
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 01:55
28 lines
1963 bytes
Greetings again,

OK,
I removed the ServiceExecute()
made sure I had a startname/password for the service
and that the Socket Property Active was true, (I tried false as well.)

But now, I have a user account problem (you mentioned this yesterday :-)

So,
I tried two user names (i.e. for the ServiceStartName and Password property for the service).

1. Using a local (administrator) user gives error at servive INSTALL time and fails to install :
" System Error. Code 1057. The account name is invalid or does not exist or the password is invalid for the account name 
specified "

2. Using my main user acount (domain based, my login for this work) installs the service OK, then fails to START with an 
error:
" Error 1069. The service did not start due to Login failure".

So,
it is something to do with user accounts and/or permissions.

Do I have to enable some user privileges somewhere ?
Does a domain user work in this context?


Quentin
Re: Removed ServiceExecute - now user account issues?
#1604
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 02:03
6 lines
1147 bytes
Aha,

Seems that I have to allow my domain account to Login as Service in the  MMC.
Does that sound right?

Q.
Re: Removed ServiceExecute - now user account issues?
#1605
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 02:11
23 lines
1646 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578c5eb@newsgroups.borland.com...

> and that the Socket Property Active was true, (I tried false as well.)

Are you setting that at design-time?  If so, then don't.  Set it
programmably in the service's OnStart event instead.

> 1. Using a local (administrator) user gives error at servive INSTALL time
> and fails to install : " System Error. Code 1057. The account name is
invalid
> or does not exist or the password is invalid for the account name
specified "

How exactly did you specify it?

> Do I have to enable some user privileges somewhere ?

No.


Gambit
Re: Server as Service - not working
#1606
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 02:39
121 lines
4637 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578bc9c$1@newsgroups.borland.com...
> Finally, here is the Server as a service.
> This version does not work.
> I suspect the inner loop in ServiceExecute.

Get rid of that event handler altogether.  Use the OnStart and
OnStop/Shutdown events to activate/deactivate the server.

And get rid of ShowMessage() as well.  You cannot use it in a service at
all.  If you must popup a message box, then you have to use MessageBox()
directly instead, so that you can specify the MB_SERVICE_NOTIFICATION flag.
Otherwise, report messages to the NT Event Log instead.

Try this code:

    void __fastcall TFileDateService::ServiceStart(TService *Sender, bool
&Started)
    {
        ServerSocket->Active = true;
        LogMessage("Socket activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
        Started = true;
    }

    void __fastcall TFileDateService::ServiceStop(TService *Sender, bool
&Stopped)
    {
        ServiceShutdown(Sender);
        Stopped = true;
    }

    void __fastcall TFileDateService::ServicePause(TService *Sender, bool
&Paused)
    {
        if( ServerSocket->Socket->ActiveConnections == 0 )
        {
            ServerSocket->Active = false;
            LogMessage("Socket de-activated for Svc pause",
EVENTLOG_INFORMATION_TYPE, 0, 0);
            Paused = true;
        }
        else
        {
            ErrCode = 1; // use whatever you want
            LogMessage("Cannot pause Svc while clients are connected to the
Socket", EVENTLOG_WARNING_TYPE, 0, 0);
            Paused = false;
        }
    }

    void __fastcall TFileDateService::ServiceContinue(TService *Sender, bool
&Continued)
    {
        if( !ServerSocket->Active )
        {
            ServerSocket->Active = true;
            LogMessage("Socket re-activated for continue",
EVENTLOG_INFORMATION_TYPE, 0, 0);
        }
        Continued = true;
    }

    void __fastcall TFileDateService::ServiceShutdown(TService *Sender)
    {
        if( ServerSocket->Active )
        {
            try
            {
                ServerSocket->Active = false;
                LogMessage("Socket de-activated", EVENTLOG_INFORMATION_TYPE,
0, 0);
            }
            catch(const Exception &e)
            {
                ErrCode = 1; // use whatever you want
                LogMessage("Socket not de-activated: " + e.Message,
EVENTLOG_ERROR_TYPE, 0, 0);
            }
        }
    }

    void __fastcall TFileDateService::ServerSocketClientRead(TObject
*Sender, TCustomWinSocket *Socket)
    {
        AnsiString FileName, FileResult;
        TSearchRec sr;

        // copy filename from client
        FileName = Socket->ReceiveText();

        // Lookup file date
        if( FindFirst(FileName, faAnyFile, sr) == 0 )
        {
            // File found - return date/time
            FindClose(sr);

            SYSTEMTIME st = {0};
            ::FileTimeToSystemTime(&sr.FindData.ftLastWriteTime, &st);

            FileResult = FileName + " date: " +
SystemTimeToDateTime(st).DateTimeString();
        }
        else
        {
            // File Not found
            FileResult = FileName + " : File Not Found";
        }

        // Now return the result to the client
        Socket->SendText(FileResult);
    }

Now, with that said, keep in mind that SendText() and ReceiveText() are very
unreliable.  They can send/receive partial data, which you have to take into
account properly to ensure that your communication is not corrupted.  Go to
http://www.deja.com and search through the newsgroup archives.  This has
been discussed in great detail many times before.


Gambit
User name login for service...
#1607
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 03:23
37 lines
1990 bytes
Hiya,

Thanks for your reply :-)

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4578c9a5$1@newsgroups.borland.com...
> Are you setting that at design-time?  If so, then don't.  Set it
> programmably in the service's OnStart event instead.

Ah, OK, will do.

>> 1. Using a local (administrator) user gives error at servive INSTALL time
>> and fails to install : " System Error. Code 1057. The account name is
> invalid
>> or does not exist or the password is invalid for the account name
> specified "
>
> How exactly did you specify it?

Simply the user name, and password, exactly as I login with - i.e.
quentin.jones
password
(using my real password)
Should it be done differently?


>> Do I have to enable some user privileges somewhere ?
>
> No.

Hmmm,
I found this page which talks about "Login as service" privilege :
http://support.microsoft.com/kb/259733

Should I try that?


Q.
Re: Server as Service - not working
#1608
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 03:25
135 lines
5126 bytes
Hiya,

thanks,
will follow that advice...

I appreciate your time and expertise Remy :-)


Q.


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4578d02b$1@newsgroups.borland.com...
>
> "Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
> message news:4578bc9c$1@newsgroups.borland.com...
>> Finally, here is the Server as a service.
>> This version does not work.
>> I suspect the inner loop in ServiceExecute.
>
> Get rid of that event handler altogether.  Use the OnStart and
> OnStop/Shutdown events to activate/deactivate the server.
>
> And get rid of ShowMessage() as well.  You cannot use it in a service at
> all.  If you must popup a message box, then you have to use MessageBox()
> directly instead, so that you can specify the MB_SERVICE_NOTIFICATION flag.
> Otherwise, report messages to the NT Event Log instead.
>
> Try this code:
>
>    void __fastcall TFileDateService::ServiceStart(TService *Sender, bool
> &Started)
>    {
>        ServerSocket->Active = true;
>        LogMessage("Socket activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
>        Started = true;
>    }
>
>    void __fastcall TFileDateService::ServiceStop(TService *Sender, bool
> &Stopped)
>    {
>        ServiceShutdown(Sender);
>        Stopped = true;
>    }
>
>    void __fastcall TFileDateService::ServicePause(TService *Sender, bool
> &Paused)
>    {
>        if( ServerSocket->Socket->ActiveConnections == 0 )
>        {
>            ServerSocket->Active = false;
>            LogMessage("Socket de-activated for Svc pause",
> EVENTLOG_INFORMATION_TYPE, 0, 0);
>            Paused = true;
>        }
>        else
>        {
>            ErrCode = 1; // use whatever you want
>            LogMessage("Cannot pause Svc while clients are connected to the
> Socket", EVENTLOG_WARNING_TYPE, 0, 0);
>            Paused = false;
>        }
>    }
>
>    void __fastcall TFileDateService::ServiceContinue(TService *Sender, bool
> &Continued)
>    {
>        if( !ServerSocket->Active )
>        {
>            ServerSocket->Active = true;
>            LogMessage("Socket re-activated for continue",
> EVENTLOG_INFORMATION_TYPE, 0, 0);
>        }
>        Continued = true;
>    }
>
>    void __fastcall TFileDateService::ServiceShutdown(TService *Sender)
>    {
>        if( ServerSocket->Active )
>        {
>            try
>            {
>                ServerSocket->Active = false;
>                LogMessage("Socket de-activated", EVENTLOG_INFORMATION_TYPE,
> 0, 0);
>            }
>            catch(const Exception &e)
>            {
>                ErrCode = 1; // use whatever you want
>                LogMessage("Socket not de-activated: " + e.Message,
> EVENTLOG_ERROR_TYPE, 0, 0);
>            }
>        }
>    }
>
>    void __fastcall TFileDateService::ServerSocketClientRead(TObject
> *Sender, TCustomWinSocket *Socket)
>    {
>        AnsiString FileName, FileResult;
>        TSearchRec sr;
>
>        // copy filename from client
>        FileName = Socket->ReceiveText();
>
>        // Lookup file date
>        if( FindFirst(FileName, faAnyFile, sr) == 0 )
>        {
>            // File found - return date/time
>            FindClose(sr);
>
>            SYSTEMTIME st = {0};
>            ::FileTimeToSystemTime(&sr.FindData.ftLastWriteTime, &st);
>
>            FileResult = FileName + " date: " +
> SystemTimeToDateTime(st).DateTimeString();
>        }
>        else
>        {
>            // File Not found
>            FileResult = FileName + " : File Not Found";
>        }
>
>        // Now return the result to the client
>        Socket->SendText(FileResult);
>    }
>
> Now, with that said, keep in mind that SendText() and ReceiveText() are very
> unreliable.  They can send/receive partial data, which you have to take into
> account properly to ensure that your communication is not corrupted.  Go to
> http://www.deja.com and search through the newsgroup archives.  This has
> been discussed in great detail many times before.
>
>
> Gambit
>
> 
Both local and domain user produce API ASync Lookup error ?
#1609
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 04:43
44 lines
2632 bytes
Hi again,

OK,
I made changes as suggested:
* start socket INactive, switched on in ServiceStart
* useEvent log for output

For user names (ServiceStartName and Password in service properties),
I have tried 3 options:
quentin.jones, password
.\quentin.jones, password
quentin.jones@romteck.com, password


I also looked under the LOGIN tab for the service, and enabled Login as Service for both
quentin.jones and
quentin.jones@romteck.com
(and asked our support people to set Login as Service for that user on the MMC.)
I know you said it wasn't needed, but I thought I try it - it didn't help.
Note: When I entered quentin.jones, it changed to .\quentin.jones, so that's why I tried that option.


So,
here is the current situation -

For BOTH local user .\quentin.jones and domain user quentin.jones@romteck.com I get the following result :

Step A - Build and install the service (command line "datesvcserver /install")
The service installs without error, and appears in the SCM.

Step B - START the service.
This produces two events immediately:
1. Application event "Socket activated" - as expected
2. ERROR event " Windows socket error: The requested name is valid and was found in the database, but it does not have 
the correct associated data being resolved for (11004), on API 'ASync Lookup'. "

Will post new code below.

What on earth is this ASync Lookup error caused by?

(Note that it only shows in Event Viewer now, not as a Windows error popup.)


Quentin
Current code - API ASync Lookup error
#1611
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 04:45
137 lines
5246 bytes
Current Code for Server Service,
produces error about API ASync Lookup in event viewer


//---------------------------------------------------------------------------
#include "DateSvc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TFileDateService *FileDateService;
//---------------------------------------------------------------------------

__fastcall TFileDateService::TFileDateService(TComponent* Owner)
 : TService(Owner)
{
}

TServiceController __fastcall TFileDateService::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}

void __stdcall ServiceController(unsigned CtrlCode)
{
 FileDateService->Controller(CtrlCode);
}

//---------------------------------------------------------------------------
// ServerSocketClientRead - called when data available for reading from client

void __fastcall TFileDateService::ServerSocketClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
   AnsiString FileName, FileResult;
   TSearchRec sr;

   // copy filename from client
   FileName = Socket->ReceiveText();

   // Lookup file date
   if( FindFirst(FileName, faAnyFile, sr) == 0 )
   {
     // File found - return date/time
     FindClose(sr);

     // Convert file time to date/time
     SYSTEMTIME st = {0};
     ::FileTimeToSystemTime(&sr.FindData.ftLastWriteTime, &st);

     // Generate result
     FileResult = FileName + " date: " + SystemTimeToDateTime(st).DateTimeString();
   }
   else
   {
     // File Not found
     FileResult = FileName + " : File Not Found";
   }

   // Now return the result to the client
   Socket->SendText(FileResult);
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStart(TService *Sender,
      bool &Started)
{
    ServerSocket->Active = true;
    LogMessage("Socket activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
    Started = true;
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceStop(TService *Sender, bool &Stopped)
{
   ServiceShutdown(Sender);
   Stopped = true;
   LogMessage("Socket DE-activated", EVENTLOG_INFORMATION_TYPE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServicePause(TService *Sender, bool &Paused)
{
  // Check if socket has active connections
  if( ServerSocket->Socket->ActiveConnections == 0 )
  {
    // No connections, de-activate
    ServerSocket->Active = false;
    LogMessage("Socket de-activated for Svc pause",
      EVENTLOG_INFORMATION_TYPE, 0, 0);
    Paused = true;
  }
  else
  {
    // Active connections - cannot pause
    ErrCode = 5555; // use whatever you want
    LogMessage("Cannot pause Svc while clients are connected to the Socket",
      EVENTLOG_WARNING_TYPE, 0, 0);
    Paused = false;
  }
}

//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceContinue(TService *Sender,
      bool &Continued)
{
  // If socket is not active, turn it on
  if( !ServerSocket->Active )
  {
    ServerSocket->Active = true;
    LogMessage("Socket re-activated for continue",
       EVENTLOG_INFORMATION_TYPE, 0, 0);
  }
  Continued = true;
}
//---------------------------------------------------------------------------
void __fastcall TFileDateService::ServiceShutdown(TService *Sender)
{
  // If socket is active, shut it down
  if( ServerSocket->Active )
  {
    // Handle exception in socket de-activate
    try
    {
      // Shutdown the socket
      ServerSocket->Active = false;
      LogMessage("Socket de-activated",
        EVENTLOG_INFORMATION_TYPE,0, 0);
    }
    catch(const Exception &e)
    {
      // Exception occured in shutodnw
      ErrCode = 5556; // use whatever you want
      LogMessage("Socket not de-activated: " + e.Message,
        EVENTLOG_ERROR_TYPE, 0, 0);
    }
  }
}
The service still starts OK? , doesn't respond to client though
#1610
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 04:48
5 lines
1270 bytes
I forgot -
even with that error event, the service still starts.
I can stop it OK, but it doesn't respond to client while running.

Q.
Does the same thing for Local System account on interactive mode...
#1612
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 04:58
8 lines
1260 bytes
Hmmm...

Did another test with an INTERACTIVE service,
thus StartServiceName and password blank.

This generates exactly the same error - the API ASync Lookup error.

Q.
Microsoft on error 11004
#1613
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 05:03
20 lines
1936 bytes
This is what Microsoft says about that error:

WSANO_DATA
11004

  Valid name, no data record of requested type.
  The requested name is valid and was found in the database, but it does not have the correct associated data being 
resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or 
WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record-indicating the 
host itself exists, but is not directly reachable.
Some issue resolving "localhost" maybe?
I just dunno.


Q.

P.S.
I guess you've gone for the weekend Remy - thanks for your very helpful advice. I am confident I can solve this with 
help such as yours (and some others - thanks guys :-)
Have a great weekend everyone :-)
Re: User name login for service...
#1614
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 05:05
15 lines
1434 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578da9b@newsgroups.borland.com...

> Simply the user name, and password, exactly as I login with - i.e.
> quentin.jones
> password
> (using my real password)
> Should it be done differently?

Yes.  If you read the documentation, the username has to be specified in
"DomainName\Username" format.


Gambit
Re: Both local and domain user produce API ASync Lookup error ?
#1615
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 05:17
39 lines
2575 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578ed46@newsgroups.borland.com...

> For user names (ServiceStartName and Password in service properties),
> I have tried 3 options:
> quentin.jones, password
> .\quentin.jones, password
> quentin.jones@romteck.com, password

If the user account is local to the machine that the service is installed
on, then use the second format above, as per the documentation.

> Step B - START the service.
> This produces two events immediately:
> 1. Application event "Socket activated" - as expected

Then the service is starting properly, and the socket is opened.

> 2. ERROR event " Windows socket error: The requested name is valid
> and was found in the database, but it does not have the correct associated
> data being resolved for (11004), on API 'ASync Lookup'. "
>
> What on earth is this ASync Lookup error caused by?

The only way for that to occur is if you have the TServerSocket's Service
property set to a non-empty string.  When you do that, TServerSocket
dynamically queries the port number that is associated with the specified
Service provider.  Obviously, you are setting the Service to an invalid
value.  You should get rid of the Service property value altogether and just
set the Port property directly instead.

> Note that it only shows in Event Viewer now, not as a Windows error popup.

As it should be.  Uncaught exceptions that occur in the context of
TService's thread will be passed to the NT Event Log.


Gambit
Re: The service still starts OK? , doesn't respond to client though
#1616
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 05:19
16 lines
1662 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578ee66$1@newsgroups.borland.com...

> even with that error event, the service still starts.

The service itself, yes.  The TServerSocket, no, as it is having problems
determining the Port number to listen on.  That is why I suggest you get rid
of the Service property value and just assign the Port directly instead.

> I can stop it OK, but it doesn't respond to client while running.

That is because the TServerSocket is not listening for clients.


Gambit
Re: Does the same thing for Local System account on interactive mode...
#1617
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 05:19
13 lines
1416 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578f0c4@newsgroups.borland.com...

> Did another test with an INTERACTIVE service,
> thus StartServiceName and password blank.
>
> This generates exactly the same error - the API ASync Lookup error.

The error has nothing to do with the service's login credentials.


Gambit
Fixed :-) Great work
#1618
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 05:40
19 lines
1863 bytes
Greetings,

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4578f53c@newsgroups.borland.com...

> The only way for that to occur is if you have the TServerSocket's Service
> property set to a non-empty string.  When you do that, TServerSocket
> dynamically queries the port number that is associated with the specified
> Service provider.  Obviously, you are setting the Service to an invalid
> value.  You should get rid of the Service property value altogether and just
> set the Port property directly instead.

Correct!
Thanks Remy :-)
I thought the service name was just a descriptive title - d'oh.
I really appreciate your time helping me get the basics going :-)

This CBuilder can be very powerful, once you get the hang of it.

Q.
Will post properties in future
#1620
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 05:45
7 lines
1287 bytes
Of course,
if I had posted the properties, the issue would have been clearer much sooner.

I'll list the relevant properties for future problems.


Q.
Roger, SendText not the best way ...
#1619
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 05:52
11 lines
1609 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4578d02b$1@newsgroups.borland.com...
> Now, with that said, keep in mind that SendText() and ReceiveText() are very
> unreliable.  They can send/receive partial data, which you have to take into
> account properly to ensure that your communication is not corrupted.  Go to
> http://www.deja.com and search through the newsgroup archives.  This has
> been discussed in great detail many times before.

Roger, I have indeed seen this mentioned,
will look it that next.

Q.
Re: Microsoft on error 11004
#1622
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 06:23
17 lines
1494 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578f20b@newsgroups.borland.com...

> This is what Microsoft says about that error:

Like I said earlier, your error is DIRECTLY related to the use of the
Service property.  That is the ONLY way that TServerSocket can be getting an
"Async Lookup" error.  Simply stop using that property and just set the Port
property directly instead.

> Some issue resolving "localhost" maybe?

No.


Gambit
Re: Fixed :-) Great work
#1623
Author: Remy Lebeau (TeamB)
Date: Fri, 08 Dec 2006 06:25
34 lines
2246 bytes
"Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
message news:4578fa92$1@newsgroups.borland.com...

> I thought the service name was just a descriptive title - d'oh.

Then I guess you didn't read the documention for the Service property yet:


    Service
    Specifies the name of the service for which the socket connection is
used.

    __property System::AnsiString Service = {read=FService,
write=SetService};

    Description
    Use Service to identify the use of the connection. Windows provides a
number of standard service names such as ftp, http, finger, and time.
Servers can specify additional services and their associated ports in a
SERVICES file. For more information, see the Microsoft documentation for
Windows sockets.

    Certain port numbers are reserved for specific values of service. Thus,
Service provides a more meaningful way to specify the server Port to use for
the socket connection. For server sockets, using Service rather than Port
ensures that the server will listen for TCP/IP requests on the appropriate
port.

    Note: Trying to change Service when the connection is open will raise an
ESocketError exception.


Gambit
Re: Fixed :-) Great work
#1624
Author: Quentin David Jones
Date: Fri, 08 Dec 2006 06:53
46 lines
2857 bytes
Indeed,

In future I will strive to carefully check all doco etc. before availing myself of your polite, patient and professional 
help :-)

Q.



"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:4579052c$1@newsgroups.borland.com...
>
> "Quentin David Jones" <quentin.jones@romteck.com.spamprotect> wrote in
> message news:4578fa92$1@newsgroups.borland.com...
>
>> I thought the service name was just a descriptive title - d'oh.
>
> Then I guess you didn't read the documention for the Service property yet:
>
>
>    Service
>    Specifies the name of the service for which the socket connection is
> used.
>
>    __property System::AnsiString Service = {read=FService,
> write=SetService};
>
>    Description
>    Use Service to identify the use of the connection. Windows provides a
> number of standard service names such as ftp, http, finger, and time.
> Servers can specify additional services and their associated ports in a
> SERVICES file. For more information, see the Microsoft documentation for
> Windows sockets.
>
>    Certain port numbers are reserved for specific values of service. Thus,
> Service provides a more meaningful way to specify the server Port to use for
> the socket connection. For server sockets, using Service rather than Port
> ensures that the server will listen for TCP/IP requests on the appropriate
> port.
>
>    Note: Trying to change Service when the connection is open will raise an
> ESocketError exception.
>
>
> Gambit
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads