bcssocket/client.c

33 lines
984 B
C

// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "include/client.h"
int main(int argc, char *argv[]) {
int fd = 0;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
printSystemError("User: socket()");
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
serv_addr.sin_addr.s_addr = inet_addr(ADDRESS);
if (connect(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
printSystemError("User: connect()");
char input[MAX_LEN] = {0};
int readChars;
while ((readChars = read(STDIN_FILENO, input, MAX_LEN - 1)) != 0) {
if (readChars < 0)
printSystemError("User: read()");
input[readChars] = '\0';
if (write(fd, input, readChars) < 0)
printSystemError("User: write()");
}
close(fd);
return EXIT_SUCCESS;
}