Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3698154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:56:49+00:00 2026-05-19T04:56:49+00:00

I write a comunication program with c/s mode in C# ,server and client program

  • 0

I write a comunication program with c/s mode in C# ,server and client program on different computer. Today after client progarm connected to server progarm ,then I pulled out cable from network adapter (after this , client and server program didn’t do anything), stranger thing happened. I found out socket of server program still keep connected status. and I use command “netstat -a -n” to retrieve network information ,and get information like following :

TCP 192.168.1.2:3645 192.168.1.3:1863 ESTABLISHED

192.168.1.2 (Server IP Address)
192.168.1.3 (Client IP Address)

Do anyone know the reason ? how to solve this problem .
I wanna how server program can receive the event and close the socket when network cable of client computer has been pulled out.

Please give me some advices or solutions.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:56:50+00:00Added an answer on May 19, 2026 at 4:56 am

    I think it can be solved by using TCP keepalive.
    refrencehttp://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html

    after connecting , set socket keepalive property . msdn say this switch default status is off , if set keepalive to on , socket will check the network status automaticly , and first check time is 2 hours after last operation on socket. but the time can be adjsut to short . then after first check , socket will servral times. if connection is down or died,
    socket will throw exception .

    C# Source:

        uint dummy = 0;
        byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
        //set keepalive on
        BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0); 
        //interval time between last operation on socket and first checking. example:5000ms=5s
        BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));
        //after first checking, socket will check serval times by 1000ms.
        BitConverter.GetBytes((uint)1000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);
    
        Socket socket = __Client.Client;
        socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
    

    I have checked. It’s running ok.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a server-client communication program and it worked well. Client module import java.io.*;
I have to write program that create process using pipe() . My first task
I need to write a program that will communicate with other .NET programs ...
EDIT: After I modified the web.config and I don't get error that's good.... then
I've build C++ program using Visual Studio 2008. Both release and debug version are
I have been experimenting with GNU Radio and came across the tunnel.py program. This
I have a problem with a simple program im making with fork and pipes
I need to write an app on Mac OS X that would send remote
I'm attempting to write a Java Servlet to receive binary data requests and reply
I would like to know what is in your opinion the best way of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.