[Plib-cvs] plib/examples/src/net/client_server README,NONE,1.1 net_udp_client.cxx,1.2,1.3 net_udp_se
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2004-03-21 17:23:38
|
Update of /cvsroot/plib/plib/examples/src/net/client_server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7848/plib/examples/src/net/client_server Modified Files: net_udp_client.cxx net_udp_server.cxx Added Files: README Log Message: Cleaned up the network library - did some improvements to the client/server example programs so that they'll actually work when you run them!! --- NEW FILE: README --- This example demonstrates a simple one-way communication path between a client and a server. It uses UDP protocol - which is unreliable but fast - don't use it for messages that utterly must get there! The client program can be told to send to the server on any port number of any host computer - by default it uses 'localhost'. The server program can be told to listen out on any port number and to either listen to just one specific client - or to accept messages from any client. Usage: net_udp_client [-p port] [servername] net_udp_server [-p port] [clientname] The default for the client is to use port 5501 on 'localhost'. The default to the server is to listen on port 5501 and to allow anyone to send to it. Index: net_udp_client.cxx =================================================================== RCS file: /cvsroot/plib/plib/examples/src/net/client_server/net_udp_client.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- net_udp_client.cxx 1 Sep 2002 12:04:51 -0000 1.2 +++ net_udp_client.cxx 21 Mar 2004 17:12:59 -0000 1.3 @@ -31,37 +31,75 @@ // time. #include <stdio.h> +#include <plib/net.h> +#include <plib/ul.h> -#include <plib/netSocket.h> +void help () +{ + fprintf ( stderr, "net_udp_client: Usage -\n" ) ; + fprintf ( stderr, "\n" ) ; [...67 lines suppressed...] + printf ( "error connecting to %s:%d\n", host, port ) ; + return -1 ; + } + + char msg[256] = "Hello world!" ; + + int len = strlen ( msg ) ; + + while ( true ) + { + ulSleep ( 1 ) ; + sock -> send( msg, len, 0 ); + printf("msg sent = %s\n", msg); + } - return 0; + return 0; } + + Index: net_udp_server.cxx =================================================================== RCS file: /cvsroot/plib/plib/examples/src/net/client_server/net_udp_server.cxx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- net_udp_server.cxx 21 Jul 2001 18:44:24 -0000 1.1 +++ net_udp_server.cxx 21 Mar 2004 17:12:59 -0000 1.2 @@ -8,41 +8,80 @@ // time. #include <stdio.h> +#include <plib/net.h> -#include <plib/netSocket.h> -int main( int argc, char **argv ) { - int port = 5501; - char host[256] = ""; // accept messages from anyone +void help () [...76 lines suppressed...] + } + + char msg [ 256 ] ; + int maxlen = 256 ; + int len ; + + while ( true ) + { + if ( (len = sock -> recv(msg, maxlen, 0)) >= 0 ) + { + msg[len] = '\0' ; + printf ( "msg received = %s\n", msg ) ; } - - return 0; + } + + return 0 ; } + |