Sockets and Threads in Borland C++ Builder4

Can anyone point me to some good code examples of how to pass a pointer to a socket into a thread.  I have a program
that is accepting request via TCP/IP and need to process
these requests and then send back info to the user.  To
speed the process I am making the program threaded so
that each request is handled independent of all the others.

Thanks

jaalexanAsked:
Who is Participating?
 
Brain2000Connect With a Mentor Commented:
Try this out.  Let me know if this is enough source code to run with.

void main(void)
{
  SOCKET s;
  DWORD junkid;

  while(1) {
    s=wait_for_connect();
    if(s!=INVALID_SOCKET) {
        h=CreateThread(NULL,0,thread_function,(LPVOID)s,0,&junkid);
        CloseHandle(h);
    }
  }
}

int WINAPI thread_function(LPVOID new_socket)
{
  SOCKET hSocket;

  hSocket=(SOCKET)new_socket;
  ...
  ...
  ...
  return(0);
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.