Hi Tim,
i tried with your inputs, still not working.
i referred en.wikipedia.org/wiki/Berkeley_sockets for my programming.
Here is my updated code: (previous post i thought definitions part will be not interest. so i didnt include)
[code]#include <stdio.h>
#include <pthread.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/iofunc.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <aio.h> // Asynchronus io libary
/* Global variables */
int SocketFD,FileFD;
struct sockaddr_in SockAddress;
int aio_flg;
struct aiocb my_aio;
char buffer[] = { “A text record to be written” },bufferread[100];
#define WAIT { while (!aio_flg); aio_flg = 0; }
static void aio_CompletionRoutine()
{
aio_flg = 1;
printf(“Triggered Aio operation completed\n”);
fflush (stdout);
}
int main( void )
{
int FD_Socket,FD_File;
int size_written,size_read;
//------------------create Socket FD -------------------------//
FD_Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (FD_Socket == -1) {
printf(“cannot create socket %d\n”,FD_Socket);
fflush (stdout);
exit(EXIT_FAILURE);
}
else
{
printf(“Opening socket successful \n”);
fflush (stdout);
}
/* Zero out socket address /
memset(&SockAddress, 0, sizeof SockAddress);
/ The address is IPv4 /
SockAddress.sin_family = AF_INET;
/ IPv4 adresses is a uint32_t, convert a string representation of the octets to the appropriate value /
SockAddress.sin_addr.s_addr = inet_addr(“127.0.0.1”);
/ sockets are unsigned shorts, htons(x) ensures x is in network byte order, set the port to 7654 */
SockAddress.sin_port = htons(7654);
/* bind: When a socket is created with socket(), it exists in a namespace (address family)
* but has no name assigned to it. The bind() function assigns a name to that unnamed socket. */
if (bind(FD_Socket, (struct sockaddr *)&SockAddress, sizeof(SockAddress)) == -1)
{
perror("error bind failed\n");
close(FD_Socket);
exit(EXIT_FAILURE);
}
else
{
printf("Binding socket successful\n");
fflush (stdout);
}
//--------------------create File FD--------------------//
FD_File = creat( "myfile.dat", S_IRUSR | S_IWUSR );
//-------------------- Data write Operation--------------------//
my_aio.aio_fildes = FD_Socket; /* Assign either Socket or File FD */
my_aio.aio_nbytes = sizeof( buffer );
my_aio.aio_buf = &buffer;
my_aio.aio_sigevent.sigev_notify = SIGEV_THREAD;
my_aio.aio_sigevent.sigev_notify_function = aio_CompletionRoutine;
size_written = aio_write(&my_aio); //Asynchronous Write Operation - File
if( size_written == -1 ) //Asynchronous Write Operation
{
perror( "Error writing myfile.dat" );
return EXIT_FAILURE;
}
else
{
printf("Data sent sucessfully -- byte sent = %d\n",sizeof( buffer ));
fflush (stdout);
WAIT; // Asynchronous Write Operation - File
}
//-------------------- Data read Operation --------------------//
FD_File = open( “myfile.dat”, O_RDONLY );
my_aio.aio_fildes = FD_Socket; /* Assign either Socket or File FD */
my_aio.aio_nbytes = sizeof( buffer );
my_aio.aio_buf = &bufferread;
my_aio.aio_sigevent.sigev_notify = SIGEV_THREAD;
my_aio.aio_sigevent.sigev_notify_function = aio_CompletionRoutine;
size_read = aio_read(&my_aio); // Asynchronous read operation
if( size_read == -1 ) {
perror( "Error reading myfile.dat" );
return EXIT_FAILURE;
}
else
{
WAIT; // Asynchronous read operation
printf("Data read sucessfully -- %s\n",&bufferread);
fflush (stdout);
}
/* close the file */
close( FD_Socket );
close( FD_File );
return EXIT_SUCCESS;
}[/code]
Hopefully it will compile for u as well.
Point 1 and 3 are working for me even with my previous command. anyhow i updated with your input.
Point 2 - i want to test it with loop back ip. Send and read through same ip. (note: i even tried with your command “INADDR_ANY”, it doesnt work)
Regarding UDP, yes data transmission is connectionless between ports. But Aio target how you send data to sockets. My thought still asynchronously can send data to sockets with UDP protocol.
Regarding your P.S: yes i found the same. But there are no concrete answers whether it will support or not. i want to ensure whether socket can be accessed asynchronously in QNX or not. Do you know how/where to confirm that?
Thanks
Sen