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

  • Home
  • SEARCH
  • 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 850323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:14:47+00:00 2026-05-15T07:14:47+00:00

I have this piece of code where a server socket is created and is

  • 0

I have this piece of code where a server socket is created and is set to listen on a particular port number say 5005. Now once the accept socket function returns the socket that gets created is copied into the m_Socket variable and finally i shutdown the server socket named SocServer which was created locally.

Now my question
Is it possible that the SocServer(created initially) and m_Socket(copied when accept returns) get the same number say 1500.

struct sockaddr_in   ServerSock;                        // Socket address structure to bind the Port Number to listen to

    char *localIP ;

    SOCKET SocServer;

    //To Set up the sockaddr structure
    ServerSock.sin_family = AF_INET;
    ServerSock.sin_addr.s_addr = INADDR_ANY    
    ServerSock.sin_port = htons(PortNumber);//port number of 5005

    // To Create a socket for listening on PortNumber
    if(( SocServer = socket( AF_INET, SOCK_STREAM, 0 )) == INVALID_SOCKET )
    {
        return FALSE;
    }

    //To bind the socket with wPortNumber
    if(bind(SocServer,(sockaddr*)&ServerSock,sizeof(ServerSock))!=0)
    {
        return FALSE;
    }

    // To Listen for the connection on wPortNumber
    if(listen(SocServer,SOMAXCONN)!=0)
    {
        return FALSE;
    }

    // Structure to get the IP Address of the connecting Entity
    sockaddr_in insock;
        int insocklen=sizeof(insock);
        //To accept the Incoming connection on the wPortNumber
    m_Socket=accept(SocServer,(struct sockaddr*)&insock,&insocklen);
     //delete the server socket
     if(SocServer != INVALID_SOCKET)
    {
        //To close and shutdown the Socserver
        shutdown(SocServer, 2 );      
        closesocket(SocServer);
    }

is it possible that Socserver and m_socket are the same because

as per my code the socket connection is established and for some other reason it gets closed and in TCPView it shows established for a while and then no connection at all.

Note: This happens only in some machines and is not reproducible always. Can any other network related issue be the cause.

  • 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-15T07:14:48+00:00Added an answer on May 15, 2026 at 7:14 am

    Are you certain that the client who is connecting to your server did not close the connection? Also, you did not provide any function which uses the m_Socket so i cannot tell you if there is any problem while handling the incoming connection. I do not think that m_socket and SocServer may end up the same.

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

Sidebar

Related Questions

I have this piece of code as part of a socks5 proxy server implementation.
I have this piece of code: <asp:Button runat=server Text=Process Payment /> When I click
I have this piece of code in a function. I want to print the
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have this piece of code for my images, so the opacity can lower
I have this piece of code, <div id=event style=display:none;> <!-- initially hidden --> <div
I have this piece of code which check the last customer_id from the db.
I have this piece of code List<Class<? extends SubApplication>> appClasses = new ArrayList<Class<? extends
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();

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.