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 870183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:25:44+00:00 2026-05-15T10:25:44+00:00

It is pure winsock server question. Just to clear that I already know how

  • 0

It is pure winsock server question. Just to clear that I already know how threads work.
I have global sockets called Global and Main_Socket.

long __stdcall newthreadfunction(); //prototype of new thread function

SOCKET Global; // To be shared and copied by thread
SOCKET Main_Socket; //main listening socket

WSADATA wsaData;
sockaddr_in service;


int main() {

........ DO STARTUP THINGS HERE ........

   Main_Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 service.sin_family = AF_INET;
 service.sin_addr.s_addr = inet_addr(IP);//"127.0.0.1"
 service.sin_port = htons(PORT);
   bind(Main_Socket, (SOCKADDR*)&service, sizeof(service));

   while(1) {
     Global = SOCKET_ERROR;
     while (Global == SOCKET_ERROR)  {
      Global = accept(Main_Socket, NULL, NULL); 
      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)newthreadfunction, 0, 0, 0);  
     }
   }
...........CLEANUP HERE ..............
}

long __stdcall newthreadfunction() {
 SOCKET Local = ?????????????????????; 

 What to do here so that the accepted connection (on Global) gets attached to 
        SOCKET Local and it starts sending and receiving independently from Global and 
        Main_Socket ??????>>>>>>>>>>>>>>>>
}

What I am trying to do is whenever I receive new connection on socket m_socket I accept it on socket Global, then start new thread and then I want a Local socket within thread to start using accepted socket on Global, and that’s all.

A quick answer or fix will be appreciated rather than links.

Bye

  • 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-15T10:25:45+00:00Added an answer on May 15, 2026 at 10:25 am

    Can’t you pass the new socket (GLOBAL) as a parameter to CreateThread?

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

Sidebar

Related Questions

Suppose I have a pure virtual method in the base interface that returns to
This question is for pure curiosity. Lets say I have lighttpd installed on my
Possible Duplicate: Pure virtual functions may not have an inline definition. Why? Just as
I have this pure CSS hover that shows a div when you rollover a
Pure virtual functions are those member functions that are virtual and have the pure-specifier
I am doing an pure AS3 programming, and I have urge to work with
I have a pure virtual class CF that denotes any continuous function in 1D
This is a pure html/css Question, here it goes.. I have a floating div
I have inherited a pure C project that uses GNU Pth ( http://www.gnu.org/software/pth/ )
I have a pure Winapi application that needs a few new features. One 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.