Article View: borland.public.cppbuilder.internet.socket
Article #1318Re: Using Winsock 2.0
From: PaoloItaly
Date: Wed, 21 Feb 2007 15:20
Date: Wed, 21 Feb 2007 15:20
132 lines
4664 bytes
4664 bytes
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;
}
Technical Details
Message-ID:
<45dc62fb$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>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a28f1afb8b745a2a X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "PaoloItaly" <paolot@FAKETHESPAMMERsirius-es.it> Newsgroups: borland.public.cppbuilder.internet.socket References: <45dc601b$1@newsgroups.borland.com> Subject: Re: Using Winsock 2.0 Date: Wed, 21 Feb 2007 16:20:39 +0100 Lines: 134 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 88.46.71.125 Message-ID: <45dc62fb$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1172071163 88.46.71.125 (21 Feb 2007 07:19:23 -0800) 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