UDP
UDP
UDP
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main() {
char buff[LEN];
struct sockaddr_in serv, cli;
int sockfd, clen = sizeof(cli), slen = sizeof(serv);
printf("\n------------SERVER------------\n");
bzero(&serv, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = htonl(INADDR_ANY);
serv.sin_port = htons(PORT);
while (1) {
int n=0;
bzero(buff, LEN);
close(sockfd);
return 0;
}
UDP CLIENT
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main() {
char buff[LEN];
struct sockaddr_in serv;
int sockfd, slen = sizeof(serv);
printf("\n------------CLIENT------------\n");
bzero(&serv, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr("127.0.0.1");
serv.sin_port = htons(PORT);
while (1) {
int n=0;
printf("Enter message to server: ");
while ((buff[n++] = getchar()) != '\n');
if (strcmp(buff, "exit") == 0) {
break;
}
bzero(buff, LEN);
close(sockfd);
return 0;
}