|
Learn. But what I write is blocking.
#include <stdio.h>
#include <stdlib.h>
#include <Winsock2.h>
void main ()
{
struct sockaddr_in test;
struct sockaddr_in re;
FILE * p = NULL;
SOCKET test1, test2;
int a, b;
WORD wVersion = MAKEWORD (2,0);
WSADATA wsData;
char buff [60];
int nResult = WSAStartup (wVersion,&wsData);
test.sin_port = 4000; // guaranteed byte order
test. sin_addr.s_addr = htonl (INADDR_ANY);
test.sin_family = AF_INET;
b = sizeof (struct sockaddr_in);
test1 = socket (AF_INET, SOCK_STREAM, 0);
if (test1 == INVALID_SOCKET)
{
exit (0);
}
a = bind (test1, (struct sockaddr *)&test, sizeof (struct sockaddr));
if (0! = a)
{
printf ("bind err\n");
exit (0);
}
a = listen (test1,1);
test2 = accept (test1, (struct sockaddr *)&re,&b);
if (test2! = INVALID_SOCKET)
{
printf ("connt\n");
}
p = fopen ("test.exe", "wb +");
while (1)
{
a = recv (test2,&buff [0], 50,0);
Ranch
if (0 == a)
{
a = WSAGetLastError ();
printf ("recv err\n");
exit (0);
} else
{
fwrite (buff, 50,1, p);
printf ("% s\n", buff);
}
}
a = send (test2,&buff [0], sizeof (buff), 0);
test2 = accept (test1, (struct sockaddr *)&re,&b);
} |
|