Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Confused about Bound sockets and deamons

Confused about Bound sockets and deamons

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelpworkspace
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Hihn
    wrote on last edited by
    #1

    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.

    L J 2 Replies Last reply
    0
    • J Jason Hihn

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Jason Hihn

        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.

        J Offline
        J Offline
        jferrell1211
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups