Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <math.h>
- #include <time.h>
- #include <string.h>
- int main(int argc, char const *argv[])
- {
- //VAR
- int FD, connFD;
- char buffer[1024];
- int occorrenze;
- //def struct
- struct sockaddr_in sock_add;
- sock_add.sin_family= AF_INET;
- sock_add.sin_port= htons(1026),
- sock_add.sin_addr.s_addr=INADDR_ANY;
- FD= socket(AF_INET, SOCK_STREAM,0);
- //bind
- bind(FD, (struct sockaddr*)&sock_add, sizeof(sock_add));
- //listen
- listen(FD, 100);
- //accept
- for(;;)
- {
- if((connFD=accept(FD, (struct sockaddr*)NULL, NULL))<0)
- {
- printf("Accept non ha funzionato\n");
- }
- read(connFD, buffer, sizeof(buffer));
- printf("%s\n",buffer );
- occorrenze=strlen(buffer);
- snprintf(buffer, sizeof(buffer), "%d", occorrenze);
- write(connFD, buffer, sizeof(buffer));
- close(connFD);
- }
- close (FD);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement