|
// SimpleSocket.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<winsock2.h>
#include<windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA WSAData={};
DWORD Status = WSAStartup(MAKEWORD(2,0), &WSAData); //initialize socket for ver 2.0
SOCKET s2=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN sa2={};
sa2.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
sa2.sin_family=AF_INET;
sa2.sin_port=htons(2300); //telnet port
Status= bind(s2,(struct sockaddr FAR*)&sa2,sizeof(sa2));
Status= listen(s2,SOMAXCONN);
int n=sizeof(sa2);
SOCKET s=accept(s2,(sockaddr FAR*) &sa2,&n);
for(int i=0;i<3;i++)
{
char buffer[100]="";
recv(s,buffer,sizeof(buffer)/2,0);
buffer[2]=0;
buffer[3]=0;
strcat(buffer,"right back at youu");
send(s,buffer,strlen(buffer),0);
}
closesocket(s2);
WSACleanup();
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.