The following simple Server opens a port on 2000 and waits for incoming connections. Each connection is answered with the same line as was written (echoed). If you want to test the server, use
telnet localhost 2000 From:http://www.adp-gmbh.ch/win/misc/sockets.html#echo// EchoServer.cpp : Defines the entry point for the console application.<br />//<br />#include "Socket.h"<br />#include <process.h><br />#include <string></p><p>DWORD WINAPI Answer(void* a)<br />{<br />Socket* s = (Socket*) a;</p><p>while (1) {<br />std::string r = s->ReceiveLine();<br />if (r.empty()) break;<br />s->SendLine(r);<br />}<br />delete s;<br />return 0;<br />}</p><p>int main(int argc, char* argv[])<br />{<br />SocketServer in(2000,5);<br />while (1)<br />{<br />Socket* s=in.Accept();<br />unsigned long ret;<br />CreateThread(0,0,Answer,(unsigned long (__stdcall *)(void *))s,0,&ret);<br />}</p><p>return 0;<br />} Dowload: http://download.csdn.net/source/1638196