online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/stat.h> #define PORT htons(2799) void HandleConnection(int gn) { int out, real; long In1; char buff[2048]; const char* mode = "r"; char str[10]; FILE *fp; if (recv(gn, &In1, sizeof(long), 0) == 0) { printf("Error while receiving!\n"); return; } real = ntohl(In1); sprintf(str, "%d", real); if (real==99){ long reed, seend, file_len, send_session; struct stat fileinfo; stat("10MB.pdf", &fileinfo); send_session = 0; fp = fopen("10MB.pdf", "rb"); file_len = fileinfo.st_size; printf("%ld", file_len); if (send(gn, &file_len, sizeof(long), 0) != sizeof(long)) { printf("Error while sending\n"); close(gn); } while (send_session < file_len) { reed = fread(buff, 1, 2048, fp); seend = send(gn, buff, reed, 0); if (reed != seend) break; send_session += seend; }} else{ fp = fopen(str, mode); fgets(buff, 2048, (FILE*)fp); if (send(gn, buff, strlen(buff), 0) != strlen(buff)) { printf("Error while sending\n"); close(gn); } fclose(fp); } } int main(void) { int gn_nasluch, gn_klienta; struct sockaddr_in adr; socklen_t dladr = sizeof(struct sockaddr_in); gn_nasluch = socket(PF_INET, SOCK_STREAM, 0); adr.sin_family = AF_INET; adr.sin_port = PORT; adr.sin_addr.s_addr = INADDR_ANY; memset(adr.sin_zero, 0, sizeof(adr.sin_zero)); if (bind(gn_nasluch, (struct sockaddr*) &adr, dladr) < 0) { printf("Port blocked \n"); return 1; } listen(gn_nasluch, 10); while(1) { dladr = sizeof(struct sockaddr_in); gn_klienta = accept(gn_nasluch, (struct sockaddr*) &adr, &dladr); if (gn_klienta < 0) printf("Connection from %s:%u\n", inet_ntoa(adr.sin_addr), ntohs(adr.sin_port) ); printf("Created child process\n"); if (fork() == 0) { HandleConnection(gn_klienta); close(gn_klienta); exit(0); } else { printf("Waiting for another connection\n"); continue; } } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue