Results 1 to 3 of 3

Thread: Winsock client/server - server socket error

Threaded View

  1. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: Winsock client/server - server socket error

    This line:
    Code:
    if (hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)==0)
    {
       // create successful ..
    is wrong.

    Code:
    if ( (hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)
    {
      // create succesful...
    is correct. In the first case, you're saying that the socket is only successfuly created if socket() returns 0. Actually, socket() returns INVALID_SOCKET if it fails to create a socket, or a handle to the socket otherwise. So the code I've written says "as long as hSocket is not INVALID_SOCKET" then creating the socket succeeded.

    Good luck!

    PS -- for more information check the msdn page on the functions you're using. For example, here is the page on socket: http://msdn2.microsoft.com/en-us/library/ms740506.aspx
    Last edited by sunburnt; Jan 19th, 2007 at 06:55 PM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width