Information Technology Reference
In-Depth Information
if (bind(s, (struct sockaddr FAR *)&sin, sizeof (sin))==SOCKET_ERROR)
{
// Bind failed
}
if (listen(s,4)<0)
{
// Listen failed
}
sin_len = sizeof(sin);
s=accept(s,(struct sockaddr FAR *) & sin,(int FAR *) &sin_len);
if (s==INVALID_SOCKET)
{
// Accept failed
}
return(0);
}
send()
The send() function sends data to a connected socket. Its syntax is:
int send (SOCKET s, const char FAR *buf, int len, int flags)
where
s
Connected socket descriptor.
buf
Transmission data buffer.
len
Buffer length.
flags
Calling flag.
The flags parameter influences the behaviour of the function. These can be
MSG_DONTROUTE Specifies that the data should not be subject to routing.
MSG_OOB Send out-of-band data.
If send() succeeds then the return value is the number of characters sent (which can be less
than the number indicated by len ). Otherwise, it returns SOCKET_ERROR , and the specific error
code can be tested with WSAGetLastError .
#include <windows.h>
#include <winsock.h>
#include <string.h>
#define STRLENGTH 100
int main(void)
{
SOCKADDR_IN sin;
SOCKET s;
int sin_len;
char sendbuf[STRLENGTH];
s = socket(AF_INET,SOCK_STREAM,0);
if (s == INVALID_SOCKET)
Search WWH ::




Custom Search