===== NetConnect ===== ==== Formato ==== **netconnect** //NombredeServidor//, //NúmerodePuerto//\\ **netconnect** ( //NombredeServidor//, //NúmerodePuerto// )\\ **netconnect** //NúmerodeSocket//, //NombredeServidor//, //NúmerodePuerto//\\ **netconnect** ( //NúmerodeSocket//, //NombredeServidor//, //NúmerodePuerto// ) ==== Descripción ==== Abre una conexión de red (cliente) con un servidor. La dirección IP o el nombre del host del servidor se especifica en el argumento //NombredeServidor//, y el número de puerto de rede en el argumento //NúmerodePuerto//. Si no se indica un //NúmerodeSocket// se utilizara el número cero (0). ==== Ejemplo ==== Abra dos instancias de BASIC-256 en un mismo equipo. Pegue el código "servidor" en una y el código "cliente" en el otro. Ejecute en primer lugar el servidor y después el cliente. Puede verse como los mensajes son enviados de un lado a otro entre los dos procesos. === Código Servidor === # get a message and send back success print "wait for connection on " + netaddress() netlisten 9997 print "got connection" do while not netdata pause .1 print "."; end while n$ = netread print n$ netwrite "I got '" + n$ + "'." until n$ = "end" netclose mostrará (donde xxx.xxx.xxx.xxx es la dirección IPv4 de su equipo): wait for connection on xxx.xxx.xxx.xxx got connection .1 Hi There ....2 Hi There ........3 Hi There ..........4 Hi There .....5 Hi There .......6 Hi There ....7 Hi There ..........8 Hi There ....9 Hi There .....10 Hi There .end === Código cliente === # el usuario debe teclear un mensaje y enviarlo al servidor input "enter message?", m$ netconnect "127.0.0.1", 9997 for t = 1 to 10 pause rand netwrite t + " " + m$ print netread next t netwrite "end" print netread netclose mostrara: enter message?Hi There I got '1 Hi There'. I got '2 Hi There'. I got '3 Hi There'. I got '4 Hi There'. I got '5 Hi There'. I got '6 Hi There'. I got '7 Hi There'. I got '8 Hi There'. I got '9 Hi There'. I got '10 Hi There'. I got 'end'. ==== Ver también ==== [[NetAddress|NetAddress]], [[NetClose|NetClose]], [[NetData|NetData]], [[NetListen|NetListen]], [[NetRead|NetRead]], [[NetWrite|NetWrite]] ==== Disponible desde la versión ==== 0.9.6.31