Skip to content

Commit

Permalink
Start server
Browse files Browse the repository at this point in the history
  • Loading branch information
sax committed Nov 26, 2012
1 parent 7ec4ddd commit aad13a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
.DS_Store

build
39 changes: 39 additions & 0 deletions server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/socket.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
int i, listenfd, connfd;
struct sockaddr_in serv_addr;

char *address = "0.0.0.0";
int port = 80;

char sendBuff[1025];
time_t ticks;

for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-p") == 0) {
port = atoi(argv[i+1]);
} else if (strcmp(argv[i], "-l") == 0) {
address = argv[i+1];
}
}

listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));

serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);

bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

listen(listenfd, 10);

printf("listen: %s:%d\n", address, port);
}

0 comments on commit aad13a7

Please sign in to comment.