Confused about Bound sockets and deamons
-
I have a program that I wrote that works like s webserver, or I want it to anyway. Clients will connect to a socket do something, then disconnect. Currently, I'm seeing weird behavior, but everythign is weird because this is new to me. First, I'm using a socket wrapper from PJ Naughter's W3Mfc project. I am under the impression that with web servers you connect to a well-known socket. Then the server 'bounces' you to a new socket so it can accept the next connection. The bounced connection is handled by a thread. In my code, I have a basic server that Bind()s, Accept()s and allows for 5 connections. In one function (and thread) I: setup the server socket, enter a while loop, wait for an accept(), do my stuff over the socket, then close it. Should I be firing off a new thread after I accept()? Originally the code was written to handle a few connections a minute, but it looks like it may do several dozen now. I'm seeing the first 6 connections get accepted.. then the next few fail, then it's spotty. Would firing off a new thread fix this? How do I Accept() and start a thread safely (how do I pass the connected socket to the new thread?) Thank you for your time.
-
I have a program that I wrote that works like s webserver, or I want it to anyway. Clients will connect to a socket do something, then disconnect. Currently, I'm seeing weird behavior, but everythign is weird because this is new to me. First, I'm using a socket wrapper from PJ Naughter's W3Mfc project. I am under the impression that with web servers you connect to a well-known socket. Then the server 'bounces' you to a new socket so it can accept the next connection. The bounced connection is handled by a thread. In my code, I have a basic server that Bind()s, Accept()s and allows for 5 connections. In one function (and thread) I: setup the server socket, enter a while loop, wait for an accept(), do my stuff over the socket, then close it. Should I be firing off a new thread after I accept()? Originally the code was written to handle a few connections a minute, but it looks like it may do several dozen now. I'm seeing the first 6 connections get accepted.. then the next few fail, then it's spotty. Would firing off a new thread fix this? How do I Accept() and start a thread safely (how do I pass the connected socket to the new thread?) Thank you for your time.
What u said about ur impression that ure "bounced" to another socket is true. And yes multithreading is a solution, but u should keep track of ur connected sockets in a linked list or stuff. In order to pass the connected socket to the working thread, u can do it when launching the thread and that by doing: AfxBeginThread ( WorkerThread , yourConnectedSocket ) ; and in the worker thread u should do a cast on the type of the socket. UINT WorkerThread ( LPVOID param ) { if(!param) return; CSocket sock = (CSocket) param; // supposing ur socket is a CSocket .... } Papa Murex Co.
-
I have a program that I wrote that works like s webserver, or I want it to anyway. Clients will connect to a socket do something, then disconnect. Currently, I'm seeing weird behavior, but everythign is weird because this is new to me. First, I'm using a socket wrapper from PJ Naughter's W3Mfc project. I am under the impression that with web servers you connect to a well-known socket. Then the server 'bounces' you to a new socket so it can accept the next connection. The bounced connection is handled by a thread. In my code, I have a basic server that Bind()s, Accept()s and allows for 5 connections. In one function (and thread) I: setup the server socket, enter a while loop, wait for an accept(), do my stuff over the socket, then close it. Should I be firing off a new thread after I accept()? Originally the code was written to handle a few connections a minute, but it looks like it may do several dozen now. I'm seeing the first 6 connections get accepted.. then the next few fail, then it's spotty. Would firing off a new thread fix this? How do I Accept() and start a thread safely (how do I pass the connected socket to the new thread?) Thank you for your time.
you are corect, the concept is known as "completion ports"....search MSDN for this term, there was a good article in MSDN Mag last year on this.....Win2K Server has API support built in for allocating blocks of ports for this... good luck 1. The Lord loves a workin' man. 2. See a doctor and get rid of it. 3. Don't trust whitey.