Re: [twsocket] TWSocket Stop Listening After Certain Numbers ofConnected Clients.
Hi Edward, Seeing as you raised this issue, and I have been experiencing the same thing, I thought I'd dedicate the day to trying to understand what is happening, and the good news is that I've managed to solve my problems, and gained a valuable understanding of the problem. Here's the thing. As a developer, you always suspect your code first don't you. Well, in my case, and maybe in yours, it's not the code. I did several tests on two Windows 2003 servers (2xQuad core, 4GB RAM, Win2003 Std Server) (one as a client and one as a server) and a Linux Server as a client, and the results were totally unexpected. I managed to get the same thing to happen, (server stopped listening), but here's the thing, it didn't really stop listening ... I could still connect a socket to the port via telnet from the Linux server, but not from the windows server. So that got me goggling ... Windows has some interesting registry settings which limit the number of OUTBOUND connections. Yip ... the outbound socket from my stress testing app was the problem, not the listening socket in the server application. Of course your server application may also have outbound sockets, as mine does, and that would simply exaggerate the problem. Anyway, this is best described in http://www.redbooks.ibm.com/redpapers/pdfs/redp3943.pdf Just look at the section under TCP TIME-WAIT Delay. Basically it says that the default Windows 2003 Server install limits the number of outbound sockets to 5000, and the TIME-WAIT to 120 seconds (That means that after a disconnect, Windows does not reuse that socket number for 120 seconds). Now, in my case I was exceeding this, and you may well be too. The good news is that you can crank these numbers up quite a bit. The number of sockets can go up to 65534, and the TIME-WAIT can come down to a few seconds if you wish with a recommendation of 30 seconds. Anyway, I'm glad that this is resolved from my perspective anyway. I hope that it works for you. Remember that you have to reboot the server before the changes will take effect. Cheers Erich -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Edward Koo Sent: Thursday, 13 September 2007 3:33 p.m. To: twsocket@elists.org; [EMAIL PROTECTED] Subject: [twsocket] TWSocket Stop Listening After Certain Numbers ofConnected Clients. Hi Wilfried, thank you for replying. How do i check how much non pageable ram is available? The test i did for Windows Server 2003 runs on a system with Xeon processor and 3gb ram. It consistently stop at 180-200 concurrent clients which is very strange compared to the other test that accepts 500-600 concurrent clients on Windows XP with single core processor and only 512mb ram. The difference i notice on the Windows Server 2003 test were that the data being received is a lot faster which makes me suspect that the main thread that listen to clients are too busy pushing data to clients and after a while the listening were timed out or something like that? Btw, after i diconnect all client i have check with netstat -n -p tcp a few times and there's no socket in WAIT_STATE at port 2 which is the port the server use and still the problem persist. It just won't accept client anymore even Netstat -a shows the server in listening state. See the following, C:\Documents and Settings\edwardkoonetstat -a Active Connections Proto Local Address Foreign Address State TCPEdward:httpEdward.N2NMSC.COM:0 LISTENING TCPEdward:epmap Edward.N2NMSC.COM:0 LISTENING TCPEdward:microsoft-dsEdward.N2NMSC.COM:0 LISTENING TCPEdward:gds_db Edward.N2NMSC.COM:0 LISTENING TCPEdward:3389Edward.N2NMSC.COM:0 LISTENING TCPEdward:2 Edward.N2NMSC.COM:0 LISTENING TCPEdward:58581 Edward.N2NMSC.COM:0 LISTENING TCPEdward:1059Edward.N2NMSC.COM:0 LISTENING C:\Documents and Settings\edwardkoonetstat -n -p tcp Active Connections Proto Local Address Foreign Address State TCP127.0.0.1:1089 127.0.0.1:1090 ESTABLISHED TCP127.0.0.1:1090 127.0.0.1:1089 ESTABLISHED TCP127.0.0.1:1091 127.0.0.1:1092 ESTABLISHED TCP127.0.0.1:1092 127.0.0.1:1091 ESTABLISHED TCP127.0.0.1:1276 127.0.0.1:9000 ESTABLISHED TCP127.0.0.1:9000 127.0.0.1:1276 ESTABLISHED TCP192.168.0.136:1106 202.75.55.43:2888 ESTABLISHED TCP192.168.0.136:1275 192.168.0.136:3050 ESTABLISHED TCP192.168.0.136:1304 192.168.0.11:135 TIME_WAIT TCP192.168.0.136:1305 192.168.0.11:1026 TIME_WAIT TCP192.168.0.136:3050 192.168.0.136:1275 ESTABLISHED I made a button that will close the listening socket and re-listen so when the problem occurs i click the button to test. After i click the button the listening will work for a while and then it will eventually stop again. I already tried catching
Re: [twsocket] Converting some perl to Delphi using sockets
Use TWSocket component to connect to the server using same parameters (127.0.0.1/TCP/1099). Then send the data in the same format, then grab the response (using OnDataAvailable event and Receive method) then gracefully close the socket (Shutdown). Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: A Drent [EMAIL PROTECTED] To: twsocket@elists.org Sent: Thursday, September 13, 2007 10:11 AM Subject: [twsocket] Converting some perl to Delphi using sockets Hi, We use a small perl script to exchange data between a webserver and an application server. I was looking to change this to Delphi. Can someone give a hint how to do this the best way using the ICS components? Best regards, Albert Drent university of Groningen use IO::Socket; # # To let this script work, please replace the PeerAddr by the # correct application server ip address (default 'localhost') and replace # the PeerPort by the correct application server port # $envString=GetEnvVariables(); $remote=IO::Socket::INET-new(Proto=tcp, PeerAddr='127.0.0.1', PeerPort='1099') or ShowError([1099] Can't connect to server); $remote-autoflush(1); binmode($remote); # # Send data to the application server # print $remote $envString; # # Retrieve data from the application server and send it back to # the web-server # binmode($remote); binmode(STDOUT); while($remote){join print; } # # ok... all done! # close($remote); # # e n d o f p r o g r a m # # -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] UDP ReceiveFrom error
Hi, I have two UDP listener sockets in a worker thread (I use a thread because is a DLL). When I receive any data in the OnDataAvailable, ReceiveFrom method call return -1 and OnDataAvailable is triggered in a infinite loop. The same code with Receive method works fine. What is wrong? Could be a bug in ReceiveFrom? Any idea? Sockets options: server1-MultiThreaded = true; //it's neccesary? server1-OnDataAvailable = SocketDataAvailable1; server1-Proto = udp; server1-Addr = 0.0.0.0; server1-MultiCast = true; server1-MultiCastAddrStr = Multicast addr; server1-ReuseAddr = true; server1-Port = PORT1; server2-MultiThreaded = true; //it's neccesary? server2-OnDataAvailable = SocketDataAvailable2; server2-Proto = udp; server2-Addr = 0.0.0.0; server2-MultiCast = true; server2-MultiCastAddrStr = Multicast addr; server2-ReuseAddr = true; server2-Port = PORT2; SocketDataAvailable1 y 2 int rec, FromIPLen; TSockAddrIn FromIP; int leidos = 0; int procesados = 0; char block[TAM_BUFFER]; std::string frame; if (Error == 0) { do { rec = server-ReceiveFrom(block, sizeof(block), FromIP, FromIPLen); //First call return -1 //rec = server-Receive(block, sizeof(block)); //With this, it works fine if (rec 0) { std::string buf; buf.assign(block, rec); frame += buf; leidos = leidos + rec; } }while (rec 0 rec == sizeof(block)); if (leidos 0) { LOGIN(Received :%s, %d., frame.c_str(), leidos); } } message pump while(!Terminated) { while (PeekMessage(msg, NULL, 0, 0, PM_REMOVE) != 0) { // Windows specific messages DispatchMessage(msg); if(msg.message == WM_QUIT) { server1-Close(); server2-Close(); this-Terminate(); break; } else if(msg.message == MY_MESSAGES) { Proccess_My_Messages } } if (!Terminated) { WaitMessage(); } } Thanks for all help. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] TWSocket Stop Listening After Certain Numbers ofConnected Clients.
Hello Erich, I see in your other mail that your problem is solved. So here I try to answer to your additional questions. What influences how much buffer RAM is used by each socket. It is the socket itself and also the data. A socket takes around 4 KB. Overlapped IO takes also pages of 4 KB but in case of lot's of data it can be more. Nothing to tell how mutch more exacly in case of mutch hi speed data. In normal circumstances you can say that a socket wich is sending and receiving will take 12 KB. Also, what is the relevance of OnBgException? OnBgException is fired when there is an exception from the middle of nowhere, that is from the message pump. If it happens then normally it will come from your code, eg an unhandled exception in some of the events. Just in case it is safe to have an event handler in it, I do always to be safe. Just put CanClose to True. Socket will close, and you you can in the OnSessionClosed handler post a message to custom message handler to re-listen, or to re-connect. Do I need to bind to it on my listening socket or my working socket? Both of them, see above. processed. Also, you talk about 1/8 of system RAM being able to be used for this buffer RAM. Is that for all applications, or is that per application. For all applications on the machine including NT services. All overlapped IO uses non pageable RAM. Also it is not only 1/8 of system RAM, it is also harware limited. But don't know the hardware limit from the top of my head. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] UDP ReceiveFrom error
Hello Wilfried, thank you for your help. I've changed my code but the problem persists. Internally RecvFrom is Result := DoRecvFrom(FHSocket, Buffer^, BufferSize, 0, From, FromLen); if Result 0 then FLastError := WSocket_Synchronized_WSAGetLastError else FReadCount := FReadCount + Result; Result is -1 and FLastError is 10014. And the event OnDataAvailable is triggered infinitely. In ICS Faq this error code is WSAEFAULT 10014 Bad address. Why it works fine with Receive but not with ReceiveFrom? There is another way to obtain the IP source? My new OnDataAvailable code is { int rec, FromIPLen; TSockAddrIn FromIP; char block[TAM_BUFFER]; //TAM_BUFFER 8192 std::string frame; if (Error == 0) { rec = server-ReceiveFrom(block, sizeof(block), FromIP, FromIPLen); //rec = server-Receive(block, sizeof(block)); if(rec 0) { frame.assign(block, rec); LOGIN(Received PORT:%s, %d., frame.c_str(), rec); } } } Thanks for all help. -Mensaje original- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] nombre de Wilfried Mestdagh Enviado el: jueves, 13 de septiembre de 2007 13:18 Para: ICS support mailing Asunto: Re: [twsocket] UDP ReceiveFrom error Hello Lorenzo, You only can call Receive or ReceiveFrom 1 time in OnDataAvailable. Don't loop in it as in your example. This could be the trouble. If you don't have received all available data then OnDataAvailable will fire again and there you receive the rest. However with UDP packet bounds are preserved, so you will receive the whole packet at once. Be sure your receiving buffer is large enough. The MultiThreaded is nececary yes. Also be sure you create and destroy TWSocket in the Execute method of the thread. If you do not you have a false thread wich can also cause troubles. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] UDP ReceiveFrom error
Hello Lorenzo, I see one bug. Possible that's the reason: FromIPLen = sizeof(FromIP); // Add this !! rec = server-ReceiveFrom(block, sizeof(block), FromIP, FromIPLen); --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be