Code
#include <stdio.h>
#include <Winsock2.h>
#pragma comment(lib, "ws2_32.lib")
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err = WSAStartup(MAKEWORD( 1, 1 ), &wsaData );
if ( err != 0 )
{
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 )
{
WSACleanup( );
return;
}
SOCKET sockClient = socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(5150);
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
send(sockClient, "Test", strlen("Test")+1,0);
char recvBuf[50];
int Rec_len = recv(sockClient,recvBuf,50,0);
if (recv(sockClient,recvBuf,50,0) != - 1)
{
printf("receive %s %d\n",recvBuf, Rec_len);
}
closesocket(sockClient);
WSACleanup();
}
#include <stdio.h>
#include <Winsock2.h>
#pragma comment(lib, "ws2_32.lib")
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err = WSAStartup(MAKEWORD( 1, 1 ), &wsaData );
if ( err != 0 )
{
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 )
{
WSACleanup( );
return;
}
SOCKET sockClient = socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(5150);
connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
send(sockClient, "Test", strlen("Test")+1,0);
char recvBuf[50];
int Rec_len = recv(sockClient,recvBuf,50,0);
if (recv(sockClient,recvBuf,50,0) != - 1)
{
printf("receive %s %d\n",recvBuf, Rec_len);
}
closesocket(sockClient);
WSACleanup();
}