Recent

Author Topic: LNet Accept failure  (Read 7867 times)

bambamns

  • Full Member
  • ***
  • Posts: 226
LNet Accept failure
« on: March 27, 2013, 08:37:37 am »
Hi ,

I made an TCP server and TCP client with LTCPComponent and it is working almost perfect.
Server is used to exchange data with several clients.

Everything is working if clients are connected one by one, but sometimes it happens that two, or more clients wont to connect to server in same second - server refuse to do it.

I tested it a lot and as I can see, if several clients wont to connect to server at same time, LTCPComponent dont fire OnAccept event, and all the other events for that connection.

I'd tried to mess with timeout value, but results are all the same.

I don't use threads - should I use it ,or there is another solution ?

Thx
« Last Edit: March 27, 2013, 08:39:56 am by bambamns »
Lazarus 3.6 on Windows 11

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: LNet Accept failure
« Reply #1 on: July 22, 2013, 01:22:33 am »
Hey, sorry to reply so long after the post, I'm mostly off pascal stuff lately.

If you're still using lNet, can you tell me which widgetset/OS this was on? There's a parameter inside Listen kernel call which specifies max connections to listen on, which could also block additionals.

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: LNet Accept failure
« Reply #2 on: August 03, 2013, 06:14:28 am »
Hi

I'm using LNet a lot in my projects.

Currently I use TLTCPComponent on Win32 and problem is present even if I try to connect just two clients in the same time.
Lazarus 3.6 on Windows 11

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: LNet Accept failure
« Reply #3 on: August 03, 2013, 06:07:15 pm »
Hi

I'm using LNet a lot in my projects.

Currently I use TLTCPComponent on Win32 and problem is present even if I try to connect just two clients in the same time.

Hi, does this behaviour occurs everytime that two client are trying to connect?

I want to build a stock count application that would run on WinCe 6.0 Datalogic device, yesterday I made client app for WinCe and Win32 with DB, using LNet tcp components, I tried to scan as much (fast) barcodes as I can, everything worked fine.

Today I compiled stress examples from LNet and when I run it from WinCe device after 50-60 to 200 connect/disconnect it crashes my app.

Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: LNet Accept failure
« Reply #4 on: August 05, 2013, 06:05:43 am »
Ye, every time , but it is matter of a couple of few ms difference between client connections - if the time connection difference is few hundred ms there is no problem.

Quote
Today I compiled stress examples from LNet and when I run it from WinCe device after 50-60 to 200 connect/disconnect it crashes my app.

What was crashed (Server or client) ?
What was the type of connection (wireless, bluetooth,GPRS ...) ?
Do you use OnCanSend event ?
Do you checked Count property (do you close connections or they are still alive ) ?
Lazarus 3.6 on Windows 11

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: LNet Accept failure
« Reply #5 on: August 06, 2013, 04:20:52 pm »
Ye, every time , but it is matter of a couple of few ms difference between client connections - if the time connection difference is few hundred ms there is no problem.

Quote
Today I compiled stress examples from LNet and when I run it from WinCe device after 50-60 to 200 connect/disconnect it crashes my app.

What was crashed (Server or client) ?
What was the type of connection (wireless, bluetooth,GPRS ...) ?
Do you use OnCanSend event ?
Do you checked Count property (do you close connections or they are still alive ) ?

Application crashed on my client Datalogic unit, it was connected on WiFi. Today I compiled again stress example for wince and it's working now. I only removed on server side this line of code:

procedure TForm1.LTCPCompAccept(aSocket: TLSocket);
begin
  UpdateLog('Konekcija prihvacena od: tran. Connection accepted from ' + aSocket.PeerAddress + ':' + IntToStr(aSocket.PeerPort));
  //lbClients.Items.AddObject(aSocket.PeerAddress, TObject(aSocket));
end;   

No, in this example I don't use OnCanSend.

Do you checked Count property (do you close connections or they are still alive ) ?

Can you explain this to me, I mean, do I have to close connections on both side?
I noticed when I run this test stress example, on client side memory allocation is the same. On server side it rises slowly.
On server side I don't have any method of closing connection, on client side is this:
 if Assigned(aSocket) then
    aSocket.Creator.Free; 

About this problem of two clients connecting at the same time, for example: can you define a variable that states that connection is established by one socket, so the next waits a few ms in while loop until the first one finishes?
Or to make them in a thread, but I read that the author abondoned this approach, now it's using single thread?

EDIT: I ve just started to keep log of Count property, it just keeps rising, until I shutdown server, then it starts from 0. How do I decrease count on server side?
« Last Edit: August 06, 2013, 04:52:15 pm by sin_dragan »
Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: LNet Accept failure
« Reply #6 on: August 06, 2013, 09:10:52 pm »
sine Dragane ... muke sa soketom  %)

Well, as first answer for socket on server side is no - you don't have to close it on server, just close it regularly on client.
To close socket on client, just do :
Code: [Select]
LTCPConponent.Disconnect(false);
Try to read this LNet manual (comments also) - it describe how to use OnCanSend event.

What "stress" example do ?
Lazarus 3.6 on Windows 11

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: LNet Accept failure
« Reply #7 on: August 06, 2013, 09:39:47 pm »
Isplatice se na kraju  :) they're hard nut but I won't give up...

Thanks for your reply, I noticed that when I disconnect from server I get an extra OnReceive event on client side fired. I ll do the way you suggested from now on.

I ve made a test app that has a TLTcpcomponent and listens on a certain port. When I run stress example and connect to my server I get only increment number of Count.

On the other side if run TcpUdp example provided by lnet author count is always 2 (sometimes 4)

This is a code for stress example:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  tcp: TLTCPComponent;
begin
  tcp := TLTCPComponent.Create(nil);
  tcp.OnConnect := @OnCo;
  tcp.Connect('192.168.1.55', 1235);
end;

procedure TForm1.OnCo(aSocket: TLSocket);
begin
  if Assigned(aSocket) then
    aSocket.Creator.Free;

  Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1);

  Button1Click(nil);
end;


On TcpUdp example the only this I noticed that is different is ReuseAddress is True, everything else is standard. (events are assigned but they only log text in memo, that's it)

But now I have different issue. Comming from Indy world,when I want to transmit data(string) I learn to first connect, send a data, quickly disconnect and then again. Here I have strange problem: When I try to connect on a separate event connection is established and then I can send data. But when I put Connect and SendMessage in same method, I always get error: Connection refused.

So this works, after connection I can transmit data:

Code: [Select]
procedure TfrmClientMain.btnConnectClick(Sender: TObject);
begin
  FNet.Host := edtIP.Text;
  FNet.Port := StrToInt(edtPort.Text);
  if (not FNet.Connected) and (FNet.Connect) then
    begin
      btnConnect.Caption := 'Disconnect';
    end
  else
    begin
      FNet.Disconnect();
      btnConnect.Caption:= 'Connect';
      UpdateLog('Disconnected from ' + FNet.Host);
    end;
end;

But on this way I get an error:

Code: [Select]
procedure TfrmClientMain.btnSendClick(Sender: TObject);
var
  Poruka: String;
begin
  FNet.Host := edtIP.Text;
  FNet.Port := StrToInt(edtPort.Text);
  if (not FNet.Connected) and FNet.Connect() then //connects okay!
    Poslato := 0;
    Poslato := FNet.SendMessage(edtCommand.Text); // Here I get an exception
end; 

Sorry if this seems long, I ll try my best and read all the material.

Cheers!
« Last Edit: August 06, 2013, 09:42:25 pm by sin_dragan »
Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

bambamns

  • Full Member
  • ***
  • Posts: 226
Re: LNet Accept failure
« Reply #8 on: August 18, 2013, 06:24:15 am »
Why do you use UDP ?

I don't have experience with UDP, I use TCP to send even few MB from HH device via GPRS to system over the internet.

At the end ....why to bother with "stress" test, write you own application test and use it - thrust me it works.
Lazarus 3.6 on Windows 11

sin_dragan

  • Full Member
  • ***
  • Posts: 127
Re: LNet Accept failure
« Reply #9 on: August 18, 2013, 03:56:40 pm »
I m using TCP protocol, TcpUdp is just the name of the example.  :)

I ve installed and got started Indy to work so I m testing currently the combination of TidCmdTCPServer and TidTcpClient. Yesterday I made a thread per connection and I query to read and write to db, so far it's working okay. Few MB via GPRS, that's great news, I know that connection speed can vary at times. Thx :)

Windows 7 64 bit
Lazarus 1.4.1 (w/fixes) FPC 2.6.4 win32

 

TinyPortal © 2005-2018