diff --git a/chat b/chat new file mode 100755 index 0000000..1772d62 Binary files /dev/null and b/chat differ diff --git a/proto.md b/proto.md index 5ef583f..65084e3 100644 --- a/proto.md +++ b/proto.md @@ -9,7 +9,7 @@ lulchat relies on HTTP, webRTC and websocket technologies. We use this in order When we refer to data types, always assume that they are being sent over the wire in network-byte order (big endian). # Usernames -Usernames must only contain alphanumeric characters, numbers, and underscores. Must contain between 3 and 21 characters. The following RegexP validates all usernames: +Usernames must only contain alphanumeric characters, numbers, and underscores. Must contain between 1 and 21 characters. The following RegexP validates all usernames: ```sh ^[A-Za-z0-9_]{1,21}$ ``` diff --git a/src/chat.c b/src/chat.c new file mode 100644 index 0000000..75f2e32 --- /dev/null +++ b/src/chat.c @@ -0,0 +1,107 @@ +#include +#include // sleep +#include +#include +#include +#include + +#define PORT 8080 + +void *loop(){ + + while(1) { + sleep(1); + printf("testing\n"); + } +} + +int main(int argc, char *argv[]){ + + int server_handle; + if((server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + + perror("Failed to create socket"); + exit(1); + } + + int opt = 1; + if( + setsockopt( + server_handle, + SOL_SOCKET, + SO_REUSEADDR | SO_REUSEPORT, + &opt, + sizeof(opt) + ) + ){ + + perror("Could not set socket options"); + exit(1); + } + + struct sockaddr_in address; + address.sin_family = AF_UNSPEC; + address.sin_addr.s_addr = INADDR_ANY; + address.sin_port = htons(PORT); + if( + ( + bind( + server_handle, + (struct sockaddr*)&address, + sizeof(address) + ) + ) < 0 + ){ + + perror("Failed to bind to socket"); + exit(1); + } + + if( + listen( + server_handle, + 3 + ) < 0 + ){ + + perror("Failed to listen to socket"); + exit(1); + } + + printf("[INFO] Listening for connections\n"); + + int client_handle; + socklen_t addrlen = sizeof(address); + //while(1){ + + if( + ( + client_handle = accept( + server_handle, + (struct sockaddr*)&address, + &addrlen + ) + ) < 0 + ){ + + perror("Failed to accept client connection"); + exit(1); + } + //} + + ssize_t buffer_read; + + while(1){ + char buffer[1024] = {0}; + buffer_read = read(client_handle, buffer, 1023); + + printf("Message (%zd): %s", buffer_read, buffer); + send(client_handle, buffer, strlen(buffer), 0); + } + + return 0; + /* + pthread_t thread_id; + pthread_create(&thread_id, NULL, loop, NULL);*/ + //pthread_join(thread_id, NULL); +} diff --git a/src/configutils.c b/src/configutils.c new file mode 100644 index 0000000..2d32240 --- /dev/null +++ b/src/configutils.c @@ -0,0 +1,6 @@ +#include + +int main(){ + + printf("boobs"); +}