Peace
Posts: 3
Joined: Fri Apr 26, 2013 12:06 pm

help please syntax?

Wed May 22, 2013 7:08 am

im trying to receive udp messages
and im new
i keep getting a syntax error at int main. main is highlighted, also should this line
int received_bytes = recvfrom( socket, packet_data, sizeof(packet_data),0, (struct sockaddr*)&
read

int received_bytes = recvfrom( handle, packet_data, sizeof(packet_data),0, (struct sockaddr*)&
?

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{    
    int handle = socket( AF_INET, SOCK_DGRAM, 0 );
    if(handle < 0){
      perror("socket");
      exit(1);
   }
    
   struct sockaddr_in servaddr;
   servaddr.sin_family = AF_INET;
   servaddr.sin_port=htons(41414);
   servaddr.sin_addr.s_addr= INADDR_ANY;

    if ( bind( handle, (struct sockaddr*)&servaddr, sizeof(servaddr) ) < 0 ){
   perror("bind");
   exit(1);
   }
           
    while ( 1 )
    {
      struct sockaddr_in cliaddr;
      char packet_data[1024];   

      socklen_t len= sizeof(cliaddr); 
      int received_bytes = recvfrom( socket, packet_data, sizeof(packet_data),0, (struct sockaddr*)&cliaddr, &len );
      if ( received_bytes > 0 )
       printf("Here is the message: %s\n",packet_data);
    }
     close(handle);
     return 0; 
}

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: help please syntax?

Wed May 22, 2013 8:29 am

That does not look like Python code.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Peace
Posts: 3
Joined: Fri Apr 26, 2013 12:06 pm

Re: help please syntax?

Wed May 22, 2013 8:59 am

thanks i found what i was looking for

Return to “Python”