diff options
-rw-r--r-- | client.c | 16 | ||||
-rw-r--r-- | listen-DGRAM.c | 5 | ||||
-rw-r--r-- | listen.c | 10 | ||||
-rwxr-xr-x | test/listen-DGRAM-t | bin | 32968 -> 37160 bytes |
4 files changed, 13 insertions, 18 deletions
@@ -17,6 +17,9 @@ #define __PORT "62000" #define BUF_SZ_2 2048 +int sockfd = -1; +size_t bytes_sent = 0; + void talk_to_server (int sockfd) { while (1) { @@ -29,19 +32,13 @@ void talk_to_server (int sockfd) { continue; } - if (editbuffer[0] == '\n') { - send(sockfd, editbuffer, fgs_len, 0); - continue; - } else { - send(sockfd, editbuffer, fgs_len, 0); - continue; - } + bytes_sent = bytes_sent + send(sockfd, editbuffer, fgs_len, 0); } } -void INThandler(int sockfd) { +void INThandler() { - fprintf(stderr, "\n"); + fprintf(stderr, "\nbytes sent: %ld\n", bytes_sent); close(sockfd); exit(0); } @@ -53,7 +50,6 @@ int main (int argc, char *argv[]) { exit(__FAIL); } - int sockfd = -1; int gai_result; int connect_result = -1; struct addrinfo hints; diff --git a/listen-DGRAM.c b/listen-DGRAM.c index 6110aa5..08f871c 100644 --- a/listen-DGRAM.c +++ b/listen-DGRAM.c @@ -16,17 +16,18 @@ #define BACKLOG 2 size_t bytes_recieved = 0; +int sockfd = -1; void INThandler() { fprintf(stderr, " SIGINT\n"); fprintf(stdout, "bytes recieved: %ld\n", bytes_recieved); + close(sockfd); exit(0); } int main () { - int sockfd = -1; // socket fd int gai_result; // result from getaddrinfo int bind_result = -1; // result from bind struct addrinfo *res; // Pointer to linked list sent back by gai @@ -51,7 +52,7 @@ int main () { continue; } - bind_result = bind(sockfd, p->ai_addr, p->ai_addrlen); // Bind to socket fd. pass our own address (ai_addr) and the length + bind_result = bind(sockfd, p->ai_addr, p->ai_addrlen); if (bind_result != 0) { fprintf(stderr, "bind_result: %d\n", bind_result); close(sockfd); @@ -77,11 +77,6 @@ int main () { if (gni == 0) { fprintf(stdout, "Client %s %s just connected!\n", host_ip, port_port); } - char *msg = "Connection established!\n"; - int len; - int bytes_sent; - len = strlen(msg); - bytes_sent = send(newfd, msg, len, 0); size_t rlen = 1024; int recv_ret; @@ -99,7 +94,10 @@ int main () { //fprintf(stdout, "loop"); memset(&recvmsg, 0, rlen); } - fprintf(stdout, "bytes recieved: %ld\nbytes sent: %d\n", bytes_recieved, bytes_sent); + if (recv_ret == -1) { + bytes_recieved = bytes_recieved + 1; + } + fprintf(stdout, "bytes recieved: %ld\n", bytes_recieved); return 0; } diff --git a/test/listen-DGRAM-t b/test/listen-DGRAM-t Binary files differindex 5f39692..1d13ae5 100755 --- a/test/listen-DGRAM-t +++ b/test/listen-DGRAM-t |