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. Sockets fail in NT Services

Sockets fail in NT Services

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 5 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 am writing a service for windows NT. The service itself works fine, but it needs to bind to a socket. The problem is CSocket::Create(port) fails every time. Does anyone know what is going on? Thanks ever so much! -Jason

    A D G C 4 Replies Last reply
    0
    • J Jason Hihn

      I am writing a service for windows NT. The service itself works fine, but it needs to bind to a socket. The problem is CSocket::Create(port) fails every time. Does anyone know what is going on? Thanks ever so much! -Jason

      A Offline
      A Offline
      Anders Molin
      wrote on last edited by
      #2

      I'm not a MFC expert (never uses it), but AFAIK CSocket doesn't work with services... You should use plain socket (all the WSA* functions) instead of the MFC wrappers... - Anders Money talks, but all mine ever says is "Goodbye!"

      1 Reply Last reply
      0
      • J Jason Hihn

        I am writing a service for windows NT. The service itself works fine, but it needs to bind to a socket. The problem is CSocket::Create(port) fails every time. Does anyone know what is going on? Thanks ever so much! -Jason

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        I've experience that some security accounts under which services run can make them fail when accessing network resources, e.g., LocalSystemAccount. Try running the service with Administrator to see if the problem is security related. BTW, what is the value of GetLastError() ? Furor fit laesa saepius patientia

        1 Reply Last reply
        0
        • J Jason Hihn

          I am writing a service for windows NT. The service itself works fine, but it needs to bind to a socket. The problem is CSocket::Create(port) fails every time. Does anyone know what is going on? Thanks ever so much! -Jason

          G Offline
          G Offline
          Giles
          wrote on last edited by
          #4

          CSocket does not work well with NT services. Check out PJ Naughters class library, which has a number of classes that are derived from his own CSocket class for use with NT services. http://www.codeproject.com/library/pj.asp I've used them quite a bit to get me out of the same situation. Hope this helps, Giles

          1 Reply Last reply
          0
          • J Jason Hihn

            I am writing a service for windows NT. The service itself works fine, but it needs to bind to a socket. The problem is CSocket::Create(port) fails every time. Does anyone know what is going on? Thanks ever so much! -Jason

            C Offline
            C Offline
            CTI
            wrote on last edited by
            #5

            Did you call AfxSockInit befofre using CSocket? Also, you may have problem making CSocket work correctly because your service is a console application. If you can make your code work in a regular MFC program (outside an NT service), then this tool by Xiangyang Liu might help you. Good luck.

            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