C:\Users\Administrator\Desktop\WinsockTests\Server\MakeFile.win Build error 1
this is the code
#include <iostream>
#include <winsock2.h>
#include <windows.h>
using namespace std;
void startServer(int PortNo)
{
char recvBuff[1024];
WSADATA wsadata;
int error;
error=WSAStartup(0x0202, &wsadata);
if (error)
{
cout << "Error occured on step 1";
system("pause");
}
if (wsadata.wVersion != 0x0202)
{
WSACleanup();
system("echo Error occured on step two");
system("pause");
}
char ServerName[30];
gethostname(ServerName,30);
SOCKET s;
cout << "(Server) " << ServerName << " is started on port " << PortNo;
SOCKADDR_IN Server;
Server.sin_family = AF_INET;
Server.sin_port = htons (PortNo);
Server.sin_addr.s_addr = inet_addr ("0.0.0.0");
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET)
{
cout << "Error occured on step 'TARGET'";
system("pause");
}
if (bind(s, (SOCKADDR *)&Server, sizeof(Server)) == SOCKET_ERROR)
{
cout << "Error Binding" << endl;
system("pause");
}
cout << endl << "Waiting for client response" << endl << endl;
while (true)
{
listen(s,2);
accept(s,NULL,NULL);
SOCKADDR_IN saClient;
memset(recvBuff, 0, sizeof(recvBuff));
int nRet = recv(s,recvBuff,1024,0);
cout << "Client said: ";
cout << recvBuff << endl;
}
closesocket(s);
}
int main(void)
{
int Port;
cout << "Port desired: ";
cin >> Port;
startServer(Port);
}

New Topic/Question
Reply


MultiQuote




|