Article View: borland.public.cppbuilder.internet.socket
Article #1319Re: Using Winsock 2.0
From: Eduardo Jauch
Date: Wed, 21 Feb 2007 15:23
Date: Wed, 21 Feb 2007 15:23
140 lines
5042 bytes
5042 bytes
PaoloItaly escreveu:
> int myWSAErrorCode(int code)
> {
> switch(code)
> {
> case WSANOTINITIALISED:
> myMessageBox("A successful WSAStartup must occur before using this
> function");
> break;
>
> case WSAENETDOWN:
> myMessageBox("The network subsystem has failed");
> break;
>
> case WSAEADDRINUSE:
> myMessageBox("The specified address is already in use");
> break;
>
> case WSAEINTR:
> myMessageBox("The (blocking) call was canceled through
> WSACancelBlockingCall");
> break;
>
> case WSAEINPROGRESS:
> myMessageBox("A blocking Windows Sockets 1.1 call is in progress,\n
> or the service provider is still processing a callback function");
> break;
>
> case WSAEALREADY:
> myMessageBox("A nonblocking connect call is in progress on the
> specified socket.\nNote In order to preserve backward compatibility, this
> error is reported as WSAEINVAL\nto Windows Sockets 1.1 applications that
> link to either WINSOCK.DLL or WSOCK32.DLL.");
> break;
>
> case WSAEADDRNOTAVAIL:
> myMessageBox("The specified address is not available from the local
> machine");
> break;
>
> case WSAEAFNOSUPPORT:
> myMessageBox("Addresses in the specified family cannot be used with
> this socket");
> break;
>
> case WSAECONNREFUSED:
> myMessageBox("The attempt to connect was forcefully rejected");
> break;
>
> case WSAEFAULT:
> myMessageBox("The name or the namelen argument is not a valid part
> of\nthe user address space, the namelen argument is too small,\nor the name
> argument contains incorrect address format for the associated address
> family");
> break;
>
> case WSAEINVAL:
> myMessageBox("The parameter s is a listening socket, or the
> destination address specified\nis not consistent with that of the
> constrained group the socket belongs to");
> break;
>
> case WSAEISCONN:
> myMessageBox("The socket is already connected (connection-oriented
> sockets only)");
> break;
>
> case WSAENETUNREACH:
> myMessageBox("The network cannot be reached from this host at this
> time");
> break;
>
> case WSAENOBUFS:
> myMessageBox("No buffer space is available. The socket cannot be
> connected");
> break;
>
> case WSAENOTSOCK:
> myMessageBox("The descriptor is not a socket");
> break;
>
> case WSAETIMEDOUT:
> myMessageBox("Attempt to connect timed out without establishing a
> connection");
> break;
>
> case WSAEWOULDBLOCK:
> myMessageBox("The socket is marked as nonblocking and the
> connection cannot be completed immediately.\nIt is possible to select the
> socket while it is connecting by selecting it for writing");
> break;
>
> case WSAEACCES:
> myMessageBox("Attempt to connect datagram socket to broadcast
> address failed because\nsetsockopt SO_BROADCAST is not enabled");
> break;
>
> default:
> code = 0;
> break;
> }
>
> if(code)
> WSASetLastError(code);
>
> return code;
> }
>
> SOCKET openSocket(unsigned short port, char ipAddr[], struct sockaddr_in
> *addr)
> {
> WORD wVersionRequested;
> WSADATA wsaData;
> SOCKET tempSock = INVALID_SOCKET;
>
> ::WSASetLastError(::WSAGetLastError());
>
> wVersionRequested = MAKEWORD(2, 0);
> if(::WSAStartup(wVersionRequested, &wsaData) == 0)
> {
> tempSock = ::socket(AF_INET, SOCK_STREAM, 0);
> if(tempSock != INVALID_SOCKET)
> {
> addr->sin_family = AF_INET;
> addr->sin_port = htons(port);
> addr->sin_addr.s_addr = inet_addr(ipAddr);
> }
>
> myWSAErrorCode(::WSAGetLastError());
> }
>
> return tempSock;
> }
>
>
HeY!!!
Thanks Paolo!!! :)
Technical Details
Message-ID:
<45dc63c7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45dc601b$1@newsgroups.borland.com> <45dc62fb$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a28f1afb8b745a2a X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 21 Feb 2007 13:23:29 -0200 From: Eduardo Jauch <eduardo.jauch@gmail.com> User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Using Winsock 2.0 References: <45dc601b$1@newsgroups.borland.com> <45dc62fb$1@newsgroups.borland.com> In-Reply-To: <45dc62fb$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 201.89.78.51 Message-ID: <45dc63c7$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1172071367 201.89.78.51 (21 Feb 2007 07:22:47 -0800) Lines: 140 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail