🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
9 messages
9 total messages Started by Arska Wed, 26 Apr 2006 08:01
Multiple serversockets in a single executable?
#2412
Author: Arska
Date: Wed, 26 Apr 2006 08:01
13 lines
1507 bytes
Hello

Is it possible to use two TServerSocket component in a single application? I
am writing a simple demonstration system, where several clients reports
their status to the server (first client-server connection). The second
client-server connection is an application where a client sends a request to
the server, which sends some data back. My server application is a single
executable. I have used two TServerSocket components. The first works ok,
but the second refuses to connect. It gives an event "On connecting", but
don't establish connection. Suggestions how to solve this. I have tested the
system in a single computer and I use ports 8001 and 8002.

Ari
Re: Multiple serversockets in a single executable?
#2414
Author: SF
Date: Wed, 26 Apr 2006 09:44
18 lines
1551 bytes
> Is it possible to use two TServerSocket component in a single 
> application?

Of course.

> executable. I have used two TServerSocket components. The 
> first works ok,
> but the second refuses to connect. It gives an event "On 
> connecting", but
> don't establish connection. Suggestions how to solve this.

You don't give enough information. Please show some code or 
write a simple application reproducing the problem and post it. 
It must be compilable so that we can try it.

Are you sure it's not a client side issue?

Stefano. 
Re: Multiple serversockets in a single executable?
#2415
Author: Remy Lebeau (TeamB)
Date: Wed, 26 Apr 2006 17:04
23 lines
1800 bytes
"Arska" <joku@eiolemassa.fi> wrote in message
news:444f28ce@newsgroups.borland.com...

> Is it possible to use two TServerSocket component in a single application?

Yes, provided that they are active on different IP/Ports from each other.

> I have used two TServerSocket components. The first works ok,
> but the second refuses to connect. It gives an event "On connecting",
> but don't establish connection.

How exactly do you have your servers configured?  Are you using them in
blocking or non-blocking mode?  Is the OnAccept event being triggered on the
second server at all?  Are you getting an OnError event triggered on the
client?  If so, which ErrorCode is it reporting?  Where are the clients
located on the network in relation to the server?  Which IP/Port are the
clients trying to connect to exactly?

Please provide more details.


Gambit
Re: Multiple serversockets in a single executable?
#2331
Author: Arska
Date: Thu, 04 May 2006 07:59
44 lines
2510 bytes
Still no solution. Now I am in a situation where server1 works ok. Server 2
establish connection, but when I send some data to it from remote client, it
gives ClientRead event ok, but when I try to read the data with
ReceiveText() it gives on exception and errorcode 10057. Connection is lost.

If I use ServerSocket->Socket->ActiveConncetions[x]->SocketHandle before
ReceiveText(), debugger says that function call is terminated  (E2122) by
unhandled exception xxxxxxx at yyyyyy

Something to do with threads?


Ari


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:444fa8da$1@newsgroups.borland.com...
>
> "Arska" <joku@eiolemassa.fi> wrote in message
> news:444f28ce@newsgroups.borland.com...
>
> > Is it possible to use two TServerSocket component in a single
application?
>
> Yes, provided that they are active on different IP/Ports from each other.
>
> > I have used two TServerSocket components. The first works ok,
> > but the second refuses to connect. It gives an event "On connecting",
> > but don't establish connection.
>
> How exactly do you have your servers configured?  Are you using them in
> blocking or non-blocking mode?  Is the OnAccept event being triggered on
the
> second server at all?  Are you getting an OnError event triggered on the
> client?  If so, which ErrorCode is it reporting?  Where are the clients
> located on the network in relation to the server?  Which IP/Port are the
> clients trying to connect to exactly?
>
> Please provide more details.
>
>
> Gambit
>
>
Re: Multiple serversockets in a single executable?
#2333
Author: Hans Galema
Date: Thu, 04 May 2006 08:12
24 lines
1981 bytes
Arska wrote:
> Still no solution. Now I am in a situation where server1 works ok. Server 2
> establish connection,

<hmm> A server accepts a connection.

> but when I send some data to it from remote client, it
> gives ClientRead event ok, but when I try to read the data with
> ReceiveText() it gives on exception and errorcode 10057. Connection is lost.

Please show your actual code for the OnRead eventhandler.

> If I use ServerSocket->Socket->ActiveConncetions[x]->SocketHandle before
> ReceiveText(), 

There is no need to use that. What do you think it would bring ?

> Something to do with threads?

Are you using threads ?

Please do not send back a whole post. Trim it.

Hans.
Re: Multiple serversockets in a single executable?
#2334
Author: Arska
Date: Thu, 04 May 2006 10:01
56 lines
2386 bytes
Now it works. I suspect, the error was a stupid misunderstanding.

void __ fastcall TForm1:: ServerSocketCliedRead( TObject *TSender,
TCustomWinSocket *Socket)

{
AnsiString buf;
...
buf = Socket->ReceiveText();

Socket->SendText(" blaa blaa")
}

instead of

void __ fastcall TForm1:: ServerSocketCliedRead( TObject *TSender,
TCustomWinSocket *Socket)

{
AnsiString buf;
...

if(ServerSocket->Socket->Connections[X]->SocketHandle ==
User[n].SocketHandle()
        buf = Socket->ReceiveText();

ServerSocket->Socket->Connections[X]->SendText(" blaa blaa")
}

Outside event handler ServerSocket->Socket works, but inside you have to use
Socket passed in a function call

Arska



"Arska" <joku@eiolemassa.fi> wrote in message
news:444f28ce@newsgroups.borland.com...
> Hello
>
> Is it possible to use two TServerSocket component in a single application?
I
> am writing a simple demonstration system, where several clients reports
> their status to the server (first client-server connection). The second
> client-server connection is an application where a client sends a request
to
> the server, which sends some data back. My server application is a single
> executable. I have used two TServerSocket components. The first works ok,
> but the second refuses to connect. It gives an event "On connecting", but
> don't establish connection. Suggestions how to solve this. I have tested
the
> system in a single computer and I use ports 8001 and 8002.
>
> Ari
>
>
Re: Multiple serversockets in a single executable?
#2335
Author: Arska
Date: Thu, 04 May 2006 12:48
66 lines
2604 bytes
My previous post is maybe difficult to understand correctly.

This is how it should be:

----------------------------------------------------------------------------
---------------------
 void __ fastcall TForm1:: ServerSocketCliedRead( TObject *TSender,
 TCustomWinSocket *Socket)

 {
 AnsiString buf;
       ...
       buf = Socket->ReceiveText();
       .. some stuff
      Socket->SendText(" blaa blaa")
//or
      Answer(Socket->SocketHandle); // example subroutine

 }

----------------------------------------------------------------------------
-------------------------- 
void Answer(int Handle)
   {
       int i;

         for(i=0;i<ServerSocket->ActiveConnections;i++)
              if(ServerSocket->Socket->Connections[i]->SocketHandle ==
Handle;
                    ServerSocket->Socket->Connections[i]->SendText("blaa
blaa");

    }

----------------------------------------------------------------------------
---------------------------


and this was how I have wrote it. The basic idea was to send answer to right
client, but it is obviously already known.
Outside event handler ServerSocket->Socket works, but inside you have to use
Socket passed in a function call.

void __ fastcall TForm1:: ServerSocketCliedRead( TObject *TSender,
 TCustomWinSocket *Socket)

 {
 AnsiString buf;
          ...
          if(ServerSocket->Socket->Connections[X]->SocketHandle ==
User[n].SocketHandle()
         buf = Socket->ReceiveText();

               ServerSocket->Socket->Connections[X]->SendText(" blaa blaa")
          }

Thanks for all that were interested for helping.


 Arska





 Arska
Re: Multiple serversockets in a single executable?
#2338
Author: Remy Lebeau (TeamB)
Date: Thu, 04 May 2006 17:45
23 lines
1688 bytes
"Arska" <joku@eiolemassa.fi> wrote in message
news:4459b46c$1@newsgroups.borland.com...

> Still no solution.

What EXACTLY are you having a problem with?  You didn't answer any of my
earlier questions.

> Now I am in a situation where server1 works ok. Server 2 establish
> connection, but when I send some data to it from remote client, it gives
> ClientRead event ok, but when I try to read the data with ReceiveText()
> it gives on exception and errorcode 10057. Connection is lost.

Please show your actual socket code.

> Something to do with threads?

TServerSocket does not use any threads by default.  You have to set it to
thread-blocking mode for that.


Gambit
Re: Multiple serversockets in a single executable?
#2337
Author: Remy Lebeau (TeamB)
Date: Thu, 04 May 2006 17:48
27 lines
1692 bytes
"Arska" <joku@eiolemassa.fi> wrote in message
news:4459f802@newsgroups.borland.com...

> This is how it should be:

No, it shouldn't.  You should not be using the Handle like that, and you
most certainly do not need to loop through the ActiveConnections looking for
the Handle while you are still inside the context of the event handler.  Use
the Socket that is provided to you, ie:

    void __ fastcall TForm1:: ServerSocketCliedRead( TObject *TSender,
TCustomWinSocket *Socket)
    {
        ...
        AnsiString buf = Socket->ReceiveText();
        ...
        Answer(Socket);
    }

    void Answer(TCustomWinSocket *Socket)
    {
        Socket->SendText("blaa blaa");
    }


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