CPPSockets 是一个 C 编写的网络类库,采用 Java 的类命名方式和接口,仿造了一个 C版本的,比如ServerSocket DatagramSocket SocketAddress。
示例代码:
int _tmain(int argc, _TCHAR* argv[]) { try { //You can use the browser ( IE, Firefox, etc. ) to visit: //http://127.0.0.1/ // simple http server ServerSocket s(80); //or //ServerSocket s; //s.bind( SocketAddress("0.0.0.0",80)); printf("listen ok\n"); Socket c2("127.0.0.1",80); while(1) { Socket c = s.accept (); printf(" Accept [%d]\n",c.GetSock() ); CloseHandle( CreateThread(0,0,clientthread,&c,0,0) );//fixme } }catch(exception e){ printf("%s",e.what()); } }