int main(int argc, char *argv[]) { #ifdef TCP int s = net_connect_tcp(NULL,"2334",0); #else int s = net_connect_udp("2334",0); #endif if (s < 0) { printf("Failed to connect (%d)\n",s); return 0; } printf("Connected to %d\nSending: %s\n",s,"Hello World"); int r; char *msg = "Hello World"; if (r = net_send(s,msg,strlen(msg)+1) < 0) { printf("Send error (%d, %d)\n",r,errno); return 0; } char *str; if ((str = net_receive(s)) == NULL) printf("Receive error (%d)\n",errno); else printf("Received: %s\n",str); closesocket(s); printf("Session terminated\n"); }
int main(int argc, char *argv[]) { #ifdef TCP int s = net_connect_tcp("0","2334",1); #else int s = net_connect_udp("2334",1); #endif if (s < 0) { printf("Failed to serve (%d)\n",s); return 0; } printf("%d serving...\n",s); #ifdef TCP int c = net_accept(s); if (c < 0) { printf("Client not found (%d)\n",c); return 0; } printf("Connected %d\n",c); char *str = net_receive(c); if (str == NULL) printf("Receive error (%d)\n",errno); else printf("Received: %s\nSending: %s\n",str,"Goodbye Cruel World"); char *msg = "Goodbye Cruel World"; if (net_send(c,msg,strlen(msg)+1) < 0) printf("Send error (%d)\n",errno); closesocket(c); #else net_bounce(s); #endif closesocket(s); printf("Session terminated\n"); }
TEG_STATUS metaserver_get_servers( void ) { int s = -1; int ret; xmlParserCtxtPtr ctxt; xmlDocPtr doc = NULL; metaserver_flush_list(); s = net_connect_tcp("teg.game-server.cc",2002); if( s < 0 ) goto error; if( net_printf( s, "GET /listServers_xml HTTP/1.1\r\n\r\n") < 0 ) goto error; ctxt = xmlCreateIOParserCtxt(NULL, NULL, (xmlInputReadCallback) net_read, (xmlInputCloseCallback) net_close, (void *)s, XML_CHAR_ENCODING_NONE); xmlParseDocument(ctxt); ret = ctxt->wellFormed; doc = ctxt->myDoc; xmlFreeParserCtxt(ctxt); if (!ret) goto error; if( metaserver_parse_xml( doc ) != TEG_STATUS_SUCCESS ) goto error; return TEG_STATUS_SUCCESS; error: if( doc ) xmlFreeDoc(doc); if( s >= 0 ) net_close( s ); return TEG_STATUS_ERROR; }