Eric Fleming Bonilha 0 Posted May 8, 2023 Hello I have a weird problem, which has haunted me for some years now and I don't know exactly why it happen or how to solve it and now we have a critical customer installation that is experiencing this issue and we can't solve it. The problem is as follow.. I have a TCP Socket Server using TWSocketServer which listens on port 8600. This socket is created and processed by the application main thread.. so, basically, all windows messages for network input on this socket is processed by the main thread... The problem happens when I have any lengthy operation going on on the same thread (main thread), so, on busy installations, we might have a process that takes 5 seconds to complete, and it is processed in the main thread (i know... it should be parallel, but for some tasks that we do it has to be in the main thread), when that happens and the main thread will "hang" for a few seconds because its doing some work, and while its doing it, obvisouly it won't respond to windows messages for new incomming connections... so, the problem happens when I have multiple incomming connections while the thread is processing something else and what actually happens is that looks like windows will stop responding to new incomming connections on port 8600, even after the thread is back from the lengthy task.. so, basically its like the socket has been closed, but all connections that are already open, will remain open and processing normally, but it will not accept new connections... in order to make it work again we have to close the socket server and open it again (make it listen to port 8600) again, then all incomming connections will work again.. The problem will never happen if new connections are not being attempted while the thread is busy... it only happens when the thread is busy and there are multiple new incomming connections while its busy. I believe that this happens because the application is not responding to windows incomming socket connection messages in a timely manner, then the OS will "close" the socket, but we never get notified in the application that this happened.. to the application, the socket is still listening.. if I go to netstat -an, it will show that port 8600 is listening.. but windows will not accept any new connection (but any connection that was already there will still communicate and work) Do you know how to fix this issue? Is there any option of the OS to not close this socket? Thanks Share this post Link to post
stijnsanders 35 Posted May 8, 2023 (edited) If you really really need to do the work on the main thread (Are you really really sure?) I would consider doing the bind and accept calls on a separate thread. It will open and accept incoming connections, so Windows gets the correct inputs and knows you still intend to work through incoming requests eventually. Do read all about thread locking and critical sections first, as you'll need it to pass requests to and from a background thread. What I would also consider, is having the work done on a main thread of a separate instance of a separate exe-file, and do CreateProcess for each incoming request. It may look like a lot of work, but will solve the 'main thread problem' and allow to handle multiple requests at once. Edited May 8, 2023 by stijnsanders Share this post Link to post
Angus Robertson 574 Posted May 8, 2023 How often are new connections being opened? There is a ListenBacklog property that is supposed to limit the pending queue of unaccepted new connections, before windows rejects new connections. It defaults to 15 in new versions of ICS. I'd also suggest using a thread for long actions, the ICS FTP server does so for certain commands that take a while on massive files. There is also a threaded server component that uses one thread per client, but it's not been tested in several years. I'm planning a new threaded server component to allow use of multiple CPUs,. Angus Share this post Link to post
Fr0sT.Brutal 900 Posted May 10, 2023 (edited) WinSock only sends one event message and then waits for some function to be called in reaction to the event. If there's a pending connect, only one FD_ACCEPT is sent until you call WSAAccept. In theory, when the message processing thread is busy the message queue could get filled and the FD_ACCEPT message won't arrive causing this behavior. But default queue limit is 10k per thread, the app unlikely has so intensive message stream to have it exhausted in 5 sec. While the reason of this hangup is the matter of question, you can try to avoid the consequences. Try manually calling WSAAccept on a server socket - it should accept the pending connection, or imitate FD_ACCEPT event with PostMessage to socket control handle. Edited May 10, 2023 by Fr0sT.Brutal Share this post Link to post
PavelOu 0 Posted January 18 Hello friends, I am here quite new .. and not expierenced in all network problematic. I have started with Delphi 7 - XE samples Ics90 from OverByte.be and I have a permanetly problem with types TWSockets.. etc., now for example with WSocketServer1: TWSocketServer; .. Type or class TWSocketServer is not included in pas sources. Can one help me to solve this problem? OverbyteIcsTcpSrv1.dfm OverbyteIcsTcpSrv1.pas Share this post Link to post
FPiette 383 Posted January 19 8 hours ago, PavelOu said: now for example with WSocketServer1: TWSocketServer; .. Type or class TWSocketServer is not included in pas sources. Do you mean there is not unit in the uses clause for TWSocketServer? There is one : OverbyteIcsTWSocketS is used. If this is not your question, please try to better explain which problem you have, which code you are using for both client and server sides. Share this post Link to post
PavelOu 0 Posted January 19 Thank you for your answer .. Yes, I meant it .. sure .. I see not your ..Gold pre-sampled yet .. so .. I attach my .dproj.2007, if it has a sinn yet .. these ones I have downloaded from Github . Icsv90-Samples-TcpSrv.zip OverbyteIcsWSocketS.pas Share this post Link to post
FPiette 383 Posted January 19 1 hour ago, PavelOu said: Thank you for your answer .. Yes, I meant it .. sure .. I see not your ..Gold pre-sampled yet .. so .. I attach my .dproj.2007, if it has a sinn yet .. these ones I have downloaded from Github . Icsv90-Samples-TcpSrv.zip OverbyteIcsWSocketS.pas Sorry, but I don't completely understand what you wrote in quite cryptic language. You should probably write a clear message in your own language and use Google translate to translate it in English. Don't download ICS from GitHUB! Download from https://wiki.overbyte.eu/wiki/index.php/ICS_Download After download, you must install the components. You should NOT have ICS sources code from several different sources: it will cause many troubles. Before installing, make sure you deleted any previous source you have and all dcu and bpl files you may have created. After installation, begin with the samples programs in ICS distribution closest to what you need and make sure they compile without error and are working as expected. Only then start coding your own application using the samples as basis. Share this post Link to post
PavelOu 0 Posted January 19 .. I try to change my cz language to en one .. I am sorry, but it is the first occurs of reclame on my language .. instead of I hope you will read my message now well .. yes I found there are many differents between Ics90 from Github and from this V7Gold .. so I must all change at first .. instead of when I have tried upack DelphiXEinstall package , some occurs of errors continued .. I attach one example ... but I did not send it .. but I cannot work with packages .. :( as you can see on Github I am skill in Modbus Rtu but Modbus TCP or so is next level for me .. instead of I have serious problem with my new device via wifi from this website : https://www.elektrobock.cz/en/thermorstat-with-wifi-module/p1731 and I need a little another program to connect it at first and read another data as this one offers in the original. Instead of I thing it can be maybe a job for you with my assistance . Share this post Link to post
FPiette 383 Posted January 19 Did you write your above message is Czech and then used Google Translate to get it in English? If you did, then Google Translate is very bad with Czech because I don't understand what you said. I'm not an English speaker either. My language is French but usually I understand English. But not your English 😞 I give up. Sorry. Share this post Link to post
PavelOu 0 Posted January 19 I am sorry for language problems .. :( .. I use windows middle europe language set .. but I did not know how to use here for example html ... I can try Google translator to French language .. as experiment .. or we can try e-mail ... Hello, I'm writing in Czech and first I'm trying to translate it into English on Google. Bonjour, j'écris en tchèque et j'essaie d'abord de le traduire en anglais sur Google. Peut-être pourrions-nous essayer le courrier électronique ? Mon e-mail est pavel.oupicky@seznam.cz. J'ai déjà essayé le V7Gold V32, mais je ne peux programmer qu'avec dpr et dfm .. donc perdu. :( Allez-vous lire le fichier txt en pièce jointe ? Essayez Windows Centre Europe. Ics90-Tool-data-2024-01-17.txt Share this post Link to post
FPiette 383 Posted January 19 OK, this is now almost correct. Forget about French translation. Use only English because I'm not the only one who can answer. What you will now do is to create a new post (not one more comment here) which clearly explain what you are trying to do, what you already done, which Delphi version you are using, which ICS version, what are the error messages you get (Never a long log file, go to the point) and more... Don't assume we know anything about your problem ! Share this post Link to post
PavelOu 0 Posted January 19 Direct : I have submitted new topic with name PPPoW simply for Delphi XE Starter . I attach two files with the different language formats and I am interested to know if you can these txt files read. From Google : I have submitted new topic with name PPPoW simply for Delphi XE Starter. I attach two files with the different language formats and I am interested to know if you can these txt files read. ICS90-OtherDemo-Ping - Results-Westeuropean.txt ICS90-OtherDemo-Ping - Results-Middleeuropean.txt Share this post Link to post
Angus Robertson 574 Posted January 19 Sorry, we rarely read files, unless the message gives information about your actual problems about ICS, then we might ask for sample code to reproduce a specific problem or logs. We still have no idea what questions you are asking here. Angus Share this post Link to post
PavelOu 0 Posted January 19 Hello Angus, at first, can you read normal this my english text? Piere did not read my text and I need to translate it via Google Tracoder .. I must orient myself hear on Delphi-Praxis .. I have tried to insert here new topic with name PPPoW , so Peer to Peer over Wifi .. maybe some one already exist here .. but I can use self only Delphi XE Starter, dpr, pas and dfm .. no more .. or prepared exe files for my PC with W10 32 bit only . So I will explain all more detailed or here or in my topic, if I find it .. soon . Share this post Link to post
FPiette 383 Posted January 20 9 hours ago, PavelOu said: Piere did not read my text and I need to translate it via Google Tracoder .. 1) My last name is Piette, not Piere. 2) I don't use Google Translate to read your text, 3) I told YOU to use Google Translate to write in English. Your latest message is better but don't contain any actual precise question. And you don't follow what I have asked. And follow what Angus asked. I won't respond here any more. Use "Start new topic" link near the top of this page to start a new message with a proper title and a proper question. Don't attach text files with long logs or more details. Don't write too much details before we ask for it. Go to the point immediately: clearly explain what you are trying to do, what you already done, which Delphi version you are using, which ICS version, what are the error messages you get. I'm really trying hard to help you but you don't read the instructions that I (Or Angus) give you. Share this post Link to post
PavelOu 0 Posted January 20 From Google : Dear Piette, I am very sorry for our language problems, but I see a problem is on your site .. as I already have writen in this my english everywhere (to China for example) and never reclaim my english .. Now I am waiting for Angus answer, if he can read my messages without translation. My question: can you read my english on Github ? Wes, I already have started in Network category my topic with name PPPoW in the begin of name of it .. Link on my topic : Share this post Link to post
Angus Robertson 574 Posted January 20 (edited) I can read your messages, but you have still not asked anything about ICS, so this will be my last message here. I've never heard of PPPoW so won't be reading your other message. It is nothing to do with Delphi or ICS. ICS has never used github. Angus Edited January 20 by Angus Robertson Share this post Link to post
PavelOu 0 Posted January 20 Hello Angus, thank you for your answer and for this confirmation, that my english is here readable . Yes I have started here my topic and I am going to public there my matter and goal. And Ics90 is or was on Github from cca juni 2023 renewed and I have downloaded a part of samples for my DXE Starter and some samples are partly still working. There is my topic started with ad hoc name PPPoW : https://en.delphipraxis.net/topic/10870-pppow-simply-for-delphi-xe-starter/?tab=comments#comment-86588 Share this post Link to post