LNet Accept failure lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- bambamns · 2013-03-27 07:37 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 ---------------------------------------------------------------------- Almindor · 2013-07-21 23:22 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 · 2013-08-03 04:14 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. ---------------------------------------------------------------------- sin_dragan · 2013-08-03 16:07 Quote from: bambamns on August 03, 2013, 06:14:28 amHi 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. ---------------------------------------------------------------------- bambamns · 2013-08-05 04:05 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. QuoteToday 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 ) ? ---------------------------------------------------------------------- sin_dragan · 2013-08-06 14:20 Quote from: bambamns on August 05, 2013, 06:05:43 amYe, 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. QuoteToday 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? ---------------------------------------------------------------------- bambamns · 2013-08-06 19:10 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 ? ---------------------------------------------------------------------- sin_dragan · 2013-08-06 19:39 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! ---------------------------------------------------------------------- bambamns · 2013-08-18 04:24 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. ---------------------------------------------------------------------- sin_dragan · 2013-08-18 13:56 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