Hi I'm trying to create and use some basic socket. I made a code but the compiler reports an error.
I'm using linux ( sys/socket.h library)
The code is>
#include <iostream>
#include <cstdlib>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <signal.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>
#include <memory.h>
#define PORT 1066
using namespace std;
int main()
{
int sock, newsock;
int i = 0;
char c, line[BUFSIZ];
struct sockaddr_in server;
int addrsize = sizeof (server);
printf("Server\n");
sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_port = htons((short)PORT);
server.sin_addr.s_addr = INADDR_ANY;
if (bind(sock, (struct sockaddr *)(&server), addrsize) == -1)
{
printf("Can't bind address to port.\n");
exit(1);
}
listen(sock, 5);
if ((newsock = accept(sock, (struct sockaddr *)(&server), &addrsize)) == -1) /* Error */
{
printf("Can't accept connection\n");
close(newsock);
newsock = -1;
}
else printf("Accepted connection\n");
while(read(newsock, &c, 1))
{
line[i++] = c;
if (c == 0)
{
line[i] = 0;
printf("Data: %s\n", line);
i = 0;
}
}
return 0;
}
The error is: error: invalid conversion from `int*' to ` socklen_t*'
It is in the line where the accept() function is called. ( 40)
help...