Jorge Inostroza
|
Re: AW: How to print a buffer into a multitext using PtSetResource
|
Jorge Inostroza
09/15/2008 11:22 AM
post13422
|
Re: AW: How to print a buffer into a multitext using PtSetResource
>>
> Sorry just realized you were receving, but unless your photon app is doing
> long operation with io_nofity you could receive the UDP stuff in your main
> application.
>
> >
yeah im receiving data, my code inside the abmain here
/*********************************************************************************************/
if (pthread_create(&child, NULL, &ChildFn1, 0) !=0){
perror("Pthreads Error");
pthread_join(child, NULL);
}
/*********************************************************************************************/
PtMainLoop( );
PtExit( 0 );
return 0;
} //end of main
/*********************************************************************************************/
void *ChildFn1(void *arg){
int Socket_con_Servidor;
Socket_con_Servidor = Abre_Conexion_Udp();
if(Socket_con_Servidor == -1){
printf("Cant establish connection with server\n");
exit(-1);
}
while(1){
Recibir_Mensaje(Socket_con_Servidor);
sleep(1);
}
return NULL;
}
/*****************************************************
//and my socket code here
int Abre_Conexion_Udp(){
struct sockaddr_in Direccion;
int sd = sizeof(Direccion);
sd = socket (AF_INET, SOCK_DGRAM, 0);
if (sd == -1){
return (-1);
}
bzero(&Direccion, sizeof(Direccion));
Direccion.sin_family = AF_INET;
Direccion.sin_port = htons(8880); //listening port
if (inet_aton("192.168.30.255", &Direccion.sin_addr) == 0)
perror("Wrong IP address");
if (bind (sd, (struct sockaddr *)&Direccion, sizeof(Direccion)) == -1){
printf("Bind problem\n");
close(sd);
return -1;
}
return (sd);
}
/******************************************************************************/
/* Receiving data from server*/
void Recibir_Mensaje(int sd){
struct sockaddr_in Servidor;
int bytes, LargoServidor = sizeof(Servidor);
char buffer[N];
memset(buffer, 0, N);
bytes = recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr *)&Servidor, &LargoServidor);
//printf("\nBuffer: %s", buffer);
PtSetResource(Multi, Pt_ARG_TEXT_STRING, buffer, 0);
memset(buffer, 0, N);
}
as you can see im trying to put the buffer received from my udp socket into a multitext, im using a thread, but when i
executed i have memory dump problems... i think this is a synchronicism problem... can anyone help me ?
|
|
|