#include #include #include #include #include "socket.h" #include "display.h" #include "audio.h" #include "typedef.h" static int fd; void on_recv(char *buf, int numbytes) { // read and play audio pid_t p = fork(); if(p < 0) { fputs("fork: failed", stderr); exit(1); } else if(p > 0) { write(fd, &(buf[REC_CAP]), numbytes-REC_CAP); } else { audio_play(buf); exit(0); } // audio_play(buf); // write(fd, &(buf[REC_CAP]), numbytes-REC_CAP); } int main(int argc, char **argv) { int pipefd[2]; if(pipe2(pipefd, O_NONBLOCK) == -1) { fputs("pipe: failed", stderr); return 1; } pid_t p = fork(); if(p < 0) { fputs("fork: failed", stderr); return 1; } else if(p > 0) { close(pipefd[0]); fd = pipefd[1]; return listener("4950", &on_recv); } else { close(pipefd[1]); display(&argc, argv, pipefd[0]); } }