Solved

non blocking socket

Posted on 2000-04-12
2
384 Views
Last Modified: 2012-05-04
i have made server in linux and my client are windows based. now when my windows client connect to my server and i remove the cable from the ethernet card, then also my server is anable to detect that cable break. I want to make myserver such that so it can detect the cable break and logout that particular user. I have used KEEPALIVE socket option but it is not working..(I have made server in 'C'language under linux through socket programming)...
0
Comment
Question by:abhishekpatel
2 Comments
 
LVL 2

Accepted Solution

by:
munsie earned 50 total points
ID: 2724795
well, you're probally TCP based for your connection.  breaking the physical connection doesn't break the logical connection.

Here's what I recommend.  Define some message that your client will send once every x seconds.  This message should be ignored by the server, but will cause a timer to reset.  If you miss 2 or more of these heartbeats, have the server close up the connection.

the easiest way to do this is to call select() on the socket with a timeout.  Se t the timeout to the same value on the client and server.  When you get a timeout, increment your missed count.

Another slightly different way is to just wait for data from the client with the timeout set, and any data sent would clear your missed count.  This would only work where the client sends data on a pretty regular interval to the server.

If the server is sending data to the client, eventually the send buffer will fill up and you will block while trying to send.  You could then use a timeout to determine that the client isn't there anymore.

good luck,
dennis
0
 

Author Comment

by:abhishekpatel
ID: 2729438
If i make the my server to wait for any data from
client that are to be used to detect the existence
of client then the "recv" call waits indifinetly if client will not send any data so my server is enable to detect it. Using "select" is good idea.
Can you guide me how to use "select" , I have tried but i don't get success.

Here is how my server works :-

        my server will fork a new process as soon as
any client connects to it so the new process will
handle all the transaction on that channel.

can you help me in implementing "select" in my server
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now