Python and UDP sockets

Zunbeltz Izaola zunbeltz at wm.lc.ehu.es.XXX
Tue Oct 21 02:46:56 EDT 2003


Hi!

I want to port a small socket aplication (in C) to Python.
The server is writen in C, and it expected to recibe and C struct
like this 


struct tag_instruccion
{
    unsigned int Handle  __attribute__  ((aligned(1)));
    int	Codigo __attribute__  ((aligned(1)));
    double Param[10]  __attribute__  ((aligned(1)));
    char Comando[_MAX_PATH] __attribute__  ((aligned(1))) ;
    char Instruc[_MAX_PATH] __attribute__  ((aligned(1))) ;
};

I know that the functions for sockets are essentialy those that are in
C (BSD sockets), but i don't know how to send this kind of struct
directly.

One of the function to send a socket is this

EnviaMensaje(SOCKET iSocket,int port,char *host, instruccion *Instruccion)
{
    struct sockaddr_in siSockAddr;
    int iRc;
    CodigoMensaje resultado;
    
    if (iSocket != INVALID_SOCKET)
    {
	memset((char *)&siSockAddr,0,sizeof(siSockAddr));
	siSockAddr.sin_family = AF_INET;
	siSockAddr.sin_port = htons(port);
	siSockAddr.sin_addr.s_addr = inet_addr(host);
	iRc = sendto(iSocket,(char const FAR *)Instruccion,sizeof(instruccion),0,(struct sockaddr FAR *)(&siSockAddr),sizeof(siSockAddr));
    }
        return iRc;
}

Can someone help me?
Thanks in advance

Zunbeltz Izaola

-- 
Remove XXX from email: zunbeltz at wm.lc.ehu.esXXX




More information about the Python-list mailing list