• Publicidad

Ayuda con el módulo Socket

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Ayuda con el módulo Socket

Notapor Unix_Sendin » 2006-05-08 18:56 @830

Mis saludos ante todo.

Bueno, sigo en lo del CGI::IRC. Ya encontré el error del Socket. Es que me falta crear el módulo Socket.pm en la carpeta /modules pero ahora viene el bateo grande. No entendí bien en la documentación que trae ActivePerl. Bueno cipé algo pero no entendí muy bien. Bueno, aquí se lo pego.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use Socket;
  2.  
  3. $proto = getprotobyname('udp');
  4. socket( Socket_Handle, PF_INET, SOCK_DGRAM, $proto );
  5. $iaddr = gethostbyname('localhost');
  6. $port  = getservbyname( 'time', 'udp' );
  7. $sin   = sockaddr_in( $port, $iaddr );
  8. send( Socket_Handle, 0, 0, $sin );
  9.  
  10. $proto = getprotobyname('tcp');
  11. socket( Socket_Handle, PF_INET, SOCK_STREAM, $proto );
  12. $port = getservbyname( 'smtp', 'tcp' );
  13. $sin = sockaddr_in( $port, inet_aton("127.1") );
  14. $sin = sockaddr_in( 7,     inet_aton("localhost") );
  15. $sin = sockaddr_in( 7,     INADDR_LOOPBACK );
  16. connect( Socket_Handle, $sin );
  17.  
  18. ( $port, $iaddr ) = sockaddr_in( getpeername(Socket_Handle) );
  19. $peer_host = gethostbyaddr( $iaddr, AF_INET );
  20. $peer_addr = inet_ntoa($iaddr);
  21.  
  22. $proto = getprotobyname('tcp');
  23. socket( Socket_Handle, PF_UNIX, SOCK_STREAM, $proto );
  24. unlink('/tmp/usock');
  25. $sun = sockaddr_un('/tmp/usock');
  26. connect( Socket_Handle, $sun );
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4

Bueno, cuando entré al webchat que doy conectar al chat no me da el error de abrir el socket pero no me entraba al chat fui a ver los logs del servidor web me salió esto.
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] Premature end of script headers: c:/appserv/www/cgi-bin/cgiirc/client-perl.cgi
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] Argument "SOCK_DGRAM" isn't numeric in socket at modules/Socket.pm line 4.\n
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] Argument "PF_INET" isn't numeric in socket at modules/Socket.pm line 4.\n
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] Undefined subroutine &main::sockaddr_in called at modules/Socket.pm line 7.\n
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] Compilation failed in require at c:\\appserv\\www\\cgi-bin\\cgiirc\\CLIENT~1.CGI line 32.\n
[Tue May 08 19:53:06 2007] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at c:\\appserv\\www\\cgi-bin\\cgiirc\\CLIENT~1.CGI line 32.\n
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] Premature end of script headers: c:/appserv/www/cgi-bin/cgiirc/client-perl.cgi
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] Argument "SOCK_DGRAM" isn't numeric in socket at modules/Socket.pm line 4.\n
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] Argument "PF_INET" isn't numeric in socket at modules/Socket.pm line 4.\n
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] Undefined subroutine &main::sockaddr_in called at modules/Socket.pm line 7.\n
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] Compilation failed in require at c:\\appserv\\www\\cgi-bin\\cgiirc\\CLIENT~1.CGI line 32.\n
[Tue May 08 19:53:07 2007] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at c:\\appserv\\www\\cgi-bin\\cgiirc\\CLIENT~1.CGI line 32.\n
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

Bueno, dígame que creen de eso. Gracias por su ayuda. :wink:
Avatar de Usuario
Unix_Sendin
Perlero nuevo
Perlero nuevo
 
Mensajes: 37
Registrado: 2006-01-29 13:03 @585
Ubicación: Cuba - Ciudad Habana

Publicidad

Notapor explorer » 2006-05-09 05:03 @252

El fallo indica que el módulo Socket no ha sido cargado o está mal.

En el servidor, ejecuta

perl -MSocket -le '$x=Socket::CRLF(); print length $x'

Si no sale un '2' en pantalla, el módulo no está o está mal instalado o tiene algún error dentro. Si ese es el caso, tendrás que instalar el paquete Socket otra vez. Prueba con

perl -MCPAN -e 'install Socket'

Por otra parte, te informo que el CGI::IRC ha tenido una actualización de seguridad hace unos días. La última versión la puedes descargar desde aquí
http://packages.debian.org/testing/net/cgiirc
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Notapor Unix_Sendin » 2006-05-09 17:32 @772

No se puede crear un socket.pm. Yo estuve leyendo pero no entendí nada. Bueno, a ver si alguien me puede ayudar a entender la configuración socket.pm o crear uno a ver si funciona. Gracias por su ayuda :wink:

Aquí tengo una web que habla como configurar el socket.pm.

http://supportweb.cs.bham.ac.uk/documen ... ocket.html
Avatar de Usuario
Unix_Sendin
Perlero nuevo
Perlero nuevo
 
Mensajes: 37
Registrado: 2006-01-29 13:03 @585
Ubicación: Cuba - Ciudad Habana

Notapor Perl user » 2006-05-09 19:25 @851

No, el problema está un poco más abajo.

Necesitas primero aprender cómo funcionan los módulos, y en general aprender un poco mas de Perl. Te recomiendo una vez hecho eso que le des una leída al módulo IO::Socket, meterte con Socket.pm te costará más trabajo.

Siempre es necesario leer teoría antes de aventarse a escupir líneas de código, puedes tener resultados más favorables que intentar caminar con los ojos tapados. Con esto me refiero a que te recomiendo leer sobre programación de aplicaciones en red y la teoría que esto conlleva.

Saludos,
Marco A. Manzo
[email protected]
http://www.unixmonkeys.com/amnesiac/
Perl Programming Language
Perl user
Maestro honorario
Maestro honorario
 
Mensajes: 271
Registrado: 2004-11-03 21:11 @924

Notapor Unix_Sendin » 2006-05-10 04:10 @215

Bueno, leer leo pero es que me es muy difícil aprender leyendo ahí muchas cosas que te quedas con dudas porque las explicaciones son muy científicas.

Yo aprendería mejor si tuviera un profesor delante que te explica a la manera que tu entiendes pero no es así pero bueno bastante que hacen manuales para mi y todos eso es un honor que ellos se esfuercen para aunque sea haya un manual en Internet.

Bueno, yo creo que el foro se hizo para ayudar a los que no saben lo que estaba leyendo de socket. No lo entiendo, por eso pedí ayuda. Si lo entendiera no pediría ayuda.

Bueno, gracias por su ayuda. Se lo agradezco. :wink:
Avatar de Usuario
Unix_Sendin
Perlero nuevo
Perlero nuevo
 
Mensajes: 37
Registrado: 2006-01-29 13:03 @585
Ubicación: Cuba - Ciudad Habana

Notapor explorer » 2006-05-10 05:16 @261

Tu no tienes que escribir el módulo Socket.pm. Ya está escrito. Lo único que tienes que hacer es instalarlo en tu servidor, como se te ha indicado más arriba.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Notapor Unix_Sendin » 2006-05-11 23:19 @013

Bueno, ya hice lo de la instalación del módulo. Aquí lo tiene.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. use Socket;
  2.  
  3. $proto = getprotobyname('tcp');
  4. socket( Socket_Handle, AF_INET, SOCK_STREAM, );
  5. $port = getservbyname( 'smtp', 'tcp' );
  6. $sin = sockaddr_in( $port, inet_aton("127.0.0.1") );
  7. $sin = sockaddr_in( 7,     inet_aton("localhost") );
  8. $sin = sockaddr_in( 7,     INADDR_LOOPBACK );
  9. connect( Socket_Handle, $sin );
  10.  
  11. ( $port, $iaddr ) = sockaddr_in( getpeername(Socket_Handle) );
  12. $peer_host = gethostbyaddr( $iaddr, AF_INET );
  13. $peer_addr = inet_ntoa($iaddr);
  14.  
  15. $proto = getprotobyname('tcp');
  16. socket( Socket_Handle, PF_UNIX, SOCK_STREAM, $proto );
  17. unlink('/var/run/usock');
  18. $sun = sockaddr_un('/var/run/usock');
  19. connect( Socket_Handle, $sun );
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

Me da este error.
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
[Sat May 12 00:13:33 2007] [error] [client 127.0.0.1] Not enough arguments for socket at C:/Perl/lib/Socket.pm line 4, near ",)"\n
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
Avatar de Usuario
Unix_Sendin
Perlero nuevo
Perlero nuevo
 
Mensajes: 37
Registrado: 2006-01-29 13:03 @585
Ubicación: Cuba - Ciudad Habana

Notapor Perl user » 2006-05-12 00:41 @070

¿Qué tal?

Mira, no quiero que pienses que tengo algo en contra de ti, estoy en las mejores disposiciones de ayudar, como siempre. Sé que le echas muchas ganas y que estás haciendo lo posible por aprender, sin embargo a veces no es suficiente con intentarlo, hay que hacerlo, y hacerlo bien.

Obviamente ese error te está diciendo cuál es el problema, y el problema es que tienes una coma volando, es decir, hay una coma que sobra en el constructor de la llamada a socket().

Si el código lo estás copiando de otra parte, te recomiendo que lo copies bien y leas para que sepas lo que realmente estás haciendo, sino, entonces haz caso de lo que los mensajes de error dicen, créeme, SIEMPRE tienen la razón.

Saludos,
Marco A. Manzo
[email protected]
http://www.unixmonkeys.com/amnesiac/
Perl Programming Language
Perl user
Maestro honorario
Maestro honorario
 
Mensajes: 271
Registrado: 2004-11-03 21:11 @924

Notapor Unix_Sendin » 2006-05-12 02:08 @130

Bueno, men, eso lo hice pero nada me da este error.
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
[Sat May 12 02:57:52 2007] [error] [client 127.0.0.1] Not enough arguments for socket at C:/Perl/lib/Socket.pm line 4, near "SOCK_STREAM)"\n
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

Bueno, aquí tengo como configurar el Socket.pm.
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
NAME

Socket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa - load the C socket.h defines and structure manipulators

SYNOPSIS

    use Socket;

    $proto = getprotobyname('udp');
    socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto);
    $iaddr = gethostbyname('hishost.com');
    $port = getservbyname('time', 'udp');
    $sin = sockaddr_in($port, $iaddr);
    send(Socket_Handle, 0, 0, $sin);

    $proto = getprotobyname('tcp');
    socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
    $port = getservbyname('smtp', 'tcp');
    $sin = sockaddr_in($port,inet_aton("127.1"));
    $sin = sockaddr_in(7,inet_aton("localhost"));
    $sin = sockaddr_in(7,INADDR_LOOPBACK);
    connect(Socket_Handle,$sin);

    ($port, $iaddr) = sockaddr_in(getpeername(Socket_Handle));
    $peer_host = gethostbyaddr($iaddr, AF_INET);
    $peer_addr = inet_ntoa($iaddr);

    $proto = getprotobyname('tcp');
    socket(Socket_Handle, PF_UNIX, SOCK_STREAM, $proto);
    unlink('/var/run/usock');
    $sun = sockaddr_un('/var/run/usock');
    connect(Socket_Handle,$sun);

DESCRIPTION ^

This module is just a translation of the C socket.h file. Unlike the old mechanism of requiring a translated socket.ph file, this uses the h2xs program (see the Perl source distribution) and your native C compiler. This means that it has a far more likely chance of getting the numbers right. This includes all of the commonly used pound-defines like AF_INET, SOCK_STREAM, etc.

Also, some common socket "newline" constants are provided: the constants CR, LF, and CRLF, as well as $CR, $LF, and $CRLF, which map to \015, \012, and \015\012. If you do not want to use the literal characters in your programs, then use the constants provided here. They are not exported by default, but can be imported individually, and with the :crlf export tag:

    use Socket qw(:DEFAULT :crlf);

In addition, some structure manipulation functions are available:

inet_aton HOSTNAME

    Takes a string giving the name of a host, and translates that to an opaque string (if programming in C, struct in_addr). Takes arguments of both the 'rtfm.mit.edu' type and '18.181.0.24'. If the host name cannot be resolved, returns undef. For multi-homed hosts (hosts with more than one address), the first address found is returned.

    For portability do not assume that the result of inet_aton() is 32 bits wide, in other words, that it would contain only the IPv4 address in network order.
inet_ntoa IP_ADDRESS

    Takes a string (an opaque string as returned by inet_aton(), or a v-string representing the four octets of the IPv4 address in network order) and translates it into a string of the form 'd.d.d.d' where the 'd's are numbers less than 256 (the normal human-readable four dotted number notation for Internet addresses).
INADDR_ANY

    Note: does not return a number, but a packed string.

    Returns the 4-byte wildcard ip address which specifies any of the hosts ip addresses. (A particular machine can have more than one ip address, each address corresponding to a particular network interface. This wildcard address allows you to bind to all of them simultaneously.) Normally equivalent to inet_aton('0.0.0.0').
INADDR_BROADCAST

    Note: does not return a number, but a packed string.

    Returns the 4-byte 'this-lan' ip broadcast address. This can be useful for some protocols to solicit information from all servers on the same LAN cable. Normally equivalent to inet_aton('255.255.255.255').
INADDR_LOOPBACK

    Note - does not return a number.

    Returns the 4-byte loopback address. Normally equivalent to inet_aton('localhost').
INADDR_NONE

    Note - does not return a number.

    Returns the 4-byte 'invalid' ip address. Normally equivalent to inet_aton('255.255.255.255').
sockaddr_family SOCKADDR

    Takes a sockaddr structure (as returned by pack_sockaddr_in(), pack_sockaddr_un() or the perl builtin functions getsockname() and getpeername()) and returns the address family tag. It will match the constant AF_INET for a sockaddr_in and AF_UNIX for a sockaddr_un. It can be used to figure out what unpacker to use for a sockaddr of unknown type.
sockaddr_in PORT, ADDRESS
sockaddr_in SOCKADDR_IN

    In a list context, unpacks its SOCKADDR_IN argument and returns an array consisting of (PORT, ADDRESS). In a scalar context, packs its (PORT, ADDRESS) arguments as a SOCKADDR_IN and returns it. If this is confusing, use pack_sockaddr_in() and unpack_sockaddr_in() explicitly.
pack_sockaddr_in PORT, IP_ADDRESS

    Takes two arguments, a port number and an opaque string, IP_ADDRESS (as returned by inet_aton(), or a v-string). Returns the sockaddr_in structure with those arguments packed in with AF_INET filled in. For Internet domain sockets, this structure is normally what you need for the arguments in bind(), connect(), and send(), and is also returned by getpeername(), getsockname() and recv().
unpack_sockaddr_in SOCKADDR_IN

    Takes a sockaddr_in structure (as returned by pack_sockaddr_in()) and returns an array of two elements: the port and an opaque string representing the IP address (you can use inet_ntoa() to convert the address to the four-dotted numeric format). Will croak if the structure does not have AF_INET in the right place.
sockaddr_un PATHNAME
sockaddr_un SOCKADDR_UN

    In a list context, unpacks its SOCKADDR_UN argument and returns an array consisting of (PATHNAME). In a scalar context, packs its PATHNAME arguments as a SOCKADDR_UN and returns it. If this is confusing, use pack_sockaddr_un() and unpack_sockaddr_un() explicitly. These are only supported if your system has <sys/un.h>.
pack_sockaddr_un PATH

    Takes one argument, a pathname. Returns the sockaddr_un structure with that path packed in with AF_UNIX filled in. For unix domain sockets, this structure is normally what you need for the arguments in bind(), connect(), and send(), and is also returned by getpeername(), getsockname() and recv().
unpack_sockaddr_un SOCKADDR_UN

    Takes a sockaddr_un structure (as returned by pack_sockaddr_un()) and returns the pathname. Will croak if the structure does not have AF_UNIX in the right place.
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

El problema es no sé inglés los traductores traducen como le da la gana. ¡Ufff!, estoy como pescado en nevera por eso es que pido ayuda.

Bueno, voy a leer esto de nuevo.

Bueno, a ver cómo traduzco esto.

Gracias por su ayuda, siempre se la agradezco.

:wink:
Avatar de Usuario
Unix_Sendin
Perlero nuevo
Perlero nuevo
 
Mensajes: 37
Registrado: 2006-01-29 13:03 @585
Ubicación: Cuba - Ciudad Habana

Notapor Perl user » 2006-05-12 10:46 @490

No era necesario copiar la documentación del módulo, está disponible de muchas maneras.

Entiendo que no sepas inglés, no es pecado, pero quizás sí estás limitándote a muchas cosas al no saberlo, y es una herramienta muy importante.

Mira, lo que yo te recomendé anteriormente era que leyeras sobre IO::Socket y que lo utilizaras en vez de Socket.pm, por muchas razones, principalmente por facilidad de uso y adaptabilidad. IO::Socket está construido a partir de Socket.pm, y Socket.pm está construido a partir de los BSD Sockets API de C, por eso es que siempre es necesario leer al respecto.

Te recomiendo leer sobre dicho tema, chécalo bien, intenta comprenderlo y cualquier duda la publicas aquí mismo.

Saludos,
Marco A. Manzo
[email protected]
http://www.unixmonkeys.com/amnesiac/
Perl Programming Language
Perl user
Maestro honorario
Maestro honorario
 
Mensajes: 271
Registrado: 2004-11-03 21:11 @924

Siguiente

Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 7 invitados

cron