Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

non blocking socket

Posted on 2000-04-12
2
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
munsie earned 200 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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