1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
SOCKADDR_IN SenderInfo;
SOCKET NewConnection;
int ClientLen = sizeof(SOCKADDR_IN);
SOCKADDR_IN ClientAddr;
int ByteReceived, nlen;
char recvbuff[1024];
NewConnection = SOCKET_ERROR;
if(NewConnection == SOCKET_ERROR)
{
NewConnection = accept(ListeningSocket, NULL, NULL);
ByteReceived = recv(NewConnection, recvbuff, sizeof(recvbuff), 0);
if (ByteReceived > 0)
{
getsockname(ListeningSocket, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
memset(&SenderInfo, 0, sizeof(SenderInfo));
nlen = sizeof(SenderInfo);
getpeername(NewConnection, (SOCKADDR *)&SenderInfo, &nlen);
char temp[10];
sprintf(temp,"service: Header- %d",Header);
OutputDebugStringA(temp);
if(Header == 99999)
{
int size = 0;
char buf[4096];
recv(NewConnection, (char*)&size, sizeof(int), 0);
sprintf(temp,"service: Filesize- %d",size);
OutputDebugStringA(temp);
int recvbyte = 0,nsum = 0;
FILE* fp = fopen("UAM_.UML","w");
while(1)
{
recvbyte = recv(NewConnection, buf,4096,0);
if(recvbyte == 0)
break;
fwrite(buf,1,recvbyte,fp);
nsum += recvbyte;
if(nsum >= size)
break;
}
fclose(fp);
}
}
}
|