Initial Commit
[Projects.git] / server / source / server.c
blob114aec2bf3438cc571773d192d3c0e92206419ef
1 #include "api.h"
3 #include <sys/socket.h>
4 #include <arpa/inet.h>
5 #include <stdarg.h>
7 #include <stdio.h>
9 int port, newsockfd, clilen, childpid, sockfd;
10 struct sockaddr_in cli_addr, serv_addr;
11 int written;
13 char * SERVER_CLOSE(char * a, char * b){
14 printf("DSJFKL:SD");
15 close(newsockfd);
16 return "";
19 char * SERVER_ACCEPT(char * a, char * b){
20 clilen = sizeof(cli_addr);
21 newsockfd = accept(newsockfd, (struct sockaddr *) &cli_addr, &clilen);
22 return "";
25 char * SERVER_WRITE(char * a, char * b){
26 written = write(newsockfd, b, strlen(b));
27 return "";
30 char * SERVER_READ(char * a, char * b) {
31 char * ptr;
32 read(newsockfd, ptr, atoi(b));
33 return ptr;
37 char * SERVER_BIND(char * a, char * b){
38 printf("BINDING\n");
39 sockfd = socket(AF_INET, SOCK_STREAM, 0);
40 port = atoi(b);
42 bzero((char *) &serv_addr, sizeof(serv_addr));
43 serv_addr.sin_family = AF_INET;
44 serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
45 serv_addr.sin_port = htons(port);
47 bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
49 listen(sockfd, 5);
50 return "";