🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5011

Re: initialising a ClientSocket

#5011
From: duncan
Date: Mon, 15 Nov 2004 11:05
119 lines
5059 bytes
Hi Vladimir Stefanovic and Hans thanks for the response, I am 
new to all this so thanks for your paitence.

My app runs on two dirrerent computers and I am trying to find 
a good way of sending files between the two applications.  I am implementing TClientSocket and TServerSocket as part of a much 
larger program and so I will try to be circumspect but as 
detailed as possible.  

Like all borland programs my application "Map" starts with...

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
   try
   {
      Application->Initialize();
      Application->CreateForm(__classid(TMap), &Map);
      Application->Run();
   }
 
etc....

TMap is a Frame that dynamically creates TClientSocket and TServerSocket in its constructor, and passes them onto another 
class (network_support) that it has just created...

NetworkSupport * ns = new NetworkSupport();
ClientSocket = new TClientSocket(this);
ServerSocket = new TServerSocket(this);
ns->set_file_components(ServerSocket, ClientSocket);

When in "NetworkSupport::set_file_components" I have the following code, the app creates a successful connection, (although it only makes the connection when TMap's "Application->Run();" is reached and not before!...

void NetworkSupport::set_file_components
(TServerSocket * const _file_server_pointer, 
    TClientSocket * const _file_client_pointer)
{
   //  Assign the components
   file_server_pointer = _file_server_pointer;
   file_client_pointer = _file_client_pointer;

   //initialise file client or file server

   if(app == cleint)
   {
      file_client_pointer->Address = "10.98.88.34";
      file_client_pointer->Port = 7017;
      file_client_pointer->Open();
   }
   else
   {
     file_server_pointer->Port = 7017;
     file_server_pointer->Active = true;
   }

   //  Assign the server events
   file_server_pointer -> OnAccept = file_server_accept;
   file_server_pointer -> OnListen = file_server_listen;
   file_server_pointer -> OnClientConnect = file_server_connect;
   file_server_pointer -> OnClientDisconnect = file_server_disconnect;
   file_server_pointer -> OnClientError = file_server_error;
   file_server_pointer -> OnClientRead = file_server_read;
   file_server_pointer -> OnClientWrite = file_server_write;
   file_server_pointer -> OnGetSocket = file_server_get_socket;
   file_server_pointer -> OnGetThread = file_server_get_thread;
   file_server_pointer -> OnThreadEnd = file_server_thread_end;

   file_server_pointer -> OnThreadStart = file_server_thread_start;


   //Assign the client events
   file_client_pointer -> OnConnect = file_client_connect;
   file_client_pointer -> OnConnecting = file_client_connecting;
   file_client_pointer -> OnDisconnect = file_client_disconnect;
   file_client_pointer -> OnError = file_client_error;
   file_client_pointer -> OnLookup = file_client_lookup;
   file_client_pointer -> OnRead = file_client_read;
   file_client_pointer -> OnWrite = file_client_write;

I then have an OnClick event that send text...

void __fastcall NetworkSupport::MyOnClick(TObject* Sender) 
{
   if(file_client_pointer->Active)
   {
      file_client_pointer->Socket->SendText("test_message");
   }//if

}

However if I try and initialise file_client_pointer in the 
OnClick event (after TMap's "Application->Run();")...

void __fastcall NetworkSupport::MyOnClick(TObject* Sender) 

{
   file_client_pointer->Address = "10.98.88.34";
   file_client_pointer->Port = 7017;
   file_client_pointer->Open();

   if(file_client_pointer->Active)
   {
      file_client_pointer->Socket->SendText("test_message");
   }//if

}//

then when file_client_pointer->Open(); is executed it calls all
 of the file_server_connect services on the server side, but not of the client events are called and 
file_client_pointer->Active remains false and the code is not executed?  

The reason I want to move the initialisation of 
file_client_pointer to the OnClick event is this is the only
place I will know the chosen ip address to send the file or 
text to. (i.e. the user chooses it from a list and then presses 
send).

Thanks and best regards,

Duncan
Technical Details
Message-ID: <41989b78$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41938125$1@newsgroups.borland.com> <4193a0bb@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f81efd77741cef0b
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "duncan" <nospam@nospan.com>
Sender: "duncan" <nospam@nospan.com>
Reply-To: "duncan" <nospam@nospan.com>
Subject: Re: initialising a ClientSocket
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 194.129.249.241     
References: <41938125$1@newsgroups.borland.com> <4193a0bb@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41989b78$1@newsgroups.borland.com>
Date: 15 Nov 2004 04:05:12 -0700
X-Trace: newsgroups.borland.com 1100520312 207.105.83.66 (15 Nov 2004 04:05:12 -0700)
Lines: 119
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail