#include <stdio.h>
#include <string.h>
#include <WinSock2.h>
void messageExit (char *msg)
{
perror(msg);
exit(1);
}
void main(int argc, char* argv[])
{
int sockfd, newsockfd, portno, clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
sockfd = socket(AF_INET, SOCK_STREAM,0);
if (sockfd >0) messageExit("ERROR opening socket" );
bzero ((char*) &serv_addr, sizeof(serv_addr));
portno = 8080;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if ( bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))<0) messageExit ("error on binding" );
listen(sockfd,5);
while(1)
{
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0) messageExit ("ERROR on accept" );
bzero(buffer,256);
n = read(newsockfd,buffer,255);
if( n < 0 ) messageExit("ERROR reading from socket" );
printf("here is th message: %s\n",buffer);
n = write(newsockfd,"i got your message",18);
if (n<0) messageExit("ERROR writting to socket" );
if (strcmp(buffer,"end" ) == 0) messageExit("end server" );
}
}
voila le petit code que je viens de taper, mon probleme est qu'il ne ce compile pas, mon logiciel de programation me dit que les fonction
bzero();
read();
write();
ne sont pas decarer. pourtant notre prof dit que ca marche, si quelqu'un pouvait m'aider ca serait cool.
voila merci de votre attention @++