Hi
I’m working with a FX30, and I trying send and receive data trought a UDP Socket, I have another device for receive and send data by UDP (tested), but I don’t receive data in any side.
I don’t find what I doing wrong.
This is my code…
#include “legato.h”
#include <strings.h>
#include <sys/types.h>
#include<netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/select.h>
#include <stdio.h> //printf
#include <string.h> //strlen
#include <sys/socket.h> //socket
#include <arpa/inet.h> //inet_addr
int sock;
#define BUFFER_SIZE 100
char incomingBuffer[BUFFER_SIZE];
char *Hola = “Hello from client”;
struct sockaddr_in servaddr;
void* UDP_SEND (void* object)
{
int s;
s = sendto(sock,(const char *)Hola, strlen(Hola),MSG_CONFIRM,(const struct sockaddr *)&servaddr, sizeof(servaddr));
if (s<0)
{
LE_INFO("SEND MSG HOLA ERROR");
return NULL;
}
LE_INFO("MSG HOLA SENDED");
return NULL;
}
void* UDP_RECIVE(void* object)
{
LE_INFO(“WAITING DATA IN UDP PORT \r\n”);
uint len;
int n;
sock = socket(AF_INET,SOCK_DGRAM,0);
bind(sock,(struct sockaddr*)&servaddr, sizeof(servaddr));
while (1)
{
//n=recvfrom(sock,(char *)&incomingBuffer, BUFFER_SIZE, 0,(struct sockaddr *)&servaddr,&len);
n=recvfrom(sock,(char *)&incomingBuffer, BUFFER_SIZE, 0,NULL,&len);
incomingBuffer[n] = '\0';
if(n < 0)
{
LE_INFO("NO DATA RECEIVED");
}
else
{
LE_INFO("SERVER : %s\n", incomingBuffer);
}
}
}
COMPONENT_INIT
{
char Ip[15] = “192.168.15.98”;
int port = 7170;
if( (sock=socket(AF_INET,SOCK_DGRAM,0)) < 0)
{
LE_INFO("SOCKET CREATION FAILED");
}
else
{
memset(&servaddr,0,sizeof(servaddr));
//Server Config
servaddr.sin_addr.s_addr=inet_addr(Ip);
servaddr.sin_port=port;
servaddr.sin_family=AF_INET;
LE_INFO("SOCKET CREATED");
pthread_t tid_UDP_Recive;
pthread_create(&tid_UDP_Recive, (pthread_attr_t*)(0), &UDP_RECIVE, (void*)(0));
pthread_t tid_UDP_Send;
pthread_create(&tid_UDP_Send, (pthread_attr_t*)(0), &UDP_SEND, (void*)(0));
}
}
I hope any one can help me.
Thanks in advance
Best Regards
Ayax Cabello