SDDSlib
|
A simple TCP client for sending commands to a server. More...
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
Go to the source code of this file.
Macros | |
#define | BUFLEN 16384 |
Functions | |
void | error_exit (const char *msg) |
int | process_command (char *buffer, int sockfd) |
int | main (int argc, char *argv[]) |
A simple TCP client for sending commands to a server.
This program establishes a TCP connection to a specified server and port, sends commands either from the command line arguments or interactively from the user, and processes the server's responses. The client supports persistent connections, allowing multiple commands to be sent over a single socket until a "disconnect" command is issued.
hostname
: The server's hostname or IP address.port
: The port number on which the server is listening.<command>
: (Optional) One or more commands to send to the server initially.If no commands are provided as arguments, the client enters an interactive mode where the user can input commands manually.
void error(const char *msg)
: Prints an error message and exits the program.int processCommand(char *buffer, int sockfd)
: Sends a command to the server and processes the response.int main(int argc, char *argv[])
: The main function that handles argument parsing, socket creation, connection, and command processing.To connect to a server at localhost
on port 8080
and send the commands HELLO
and STATUS
:
After sending the initial commands, the client will enter interactive mode where additional commands can be entered until disconnect
is typed.
Definition in file sddslogclient.c.
#define BUFLEN 16384 |
Definition at line 64 of file sddslogclient.c.
void error_exit | ( | const char * | msg | ) |
Definition at line 67 of file sddslogclient.c.
int main | ( | int | argc, |
char * | argv[] ) |
Definition at line 90 of file sddslogclient.c.
int process_command | ( | char * | buffer, |
int | sockfd ) |
Definition at line 73 of file sddslogclient.c.