diff options
| author | Joseph Henry <[email protected]> | 2016-10-28 16:42:19 -0700 |
|---|---|---|
| committer | Joseph Henry <[email protected]> | 2016-10-28 16:42:19 -0700 |
| commit | c5a66be7aa8463e3da4060fe17adf6031ce2edf5 (patch) | |
| tree | 09a2a07b686896e54d5ac50b891e404e69a3809b /tests/api_test/tcpclient4.c | |
| parent | 92c945aee33efad0278fa4115d6e834bf2b9345a (diff) | |
picotcp/lwip ipv4/ipv6 fully functional, needs stress testing0.6.1
Diffstat (limited to 'tests/api_test/tcpclient4.c')
| -rw-r--r-- | tests/api_test/tcpclient4.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/api_test/tcpclient4.c b/tests/api_test/tcpclient4.c new file mode 100644 index 0000000..c8ec00c --- /dev/null +++ b/tests/api_test/tcpclient4.c @@ -0,0 +1,49 @@ +// TCP Client test program + +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#include <arpa/inet.h> + +int atoi(const char *str); +int close(int filedes); + +int main(int argc , char *argv[]) +{ + if(argc < 3) { + printf("usage: client <addr> <port>\n"); + return 1; + } + + int sock, port = atoi(argv[2]); + struct sockaddr_in server; + char message[1000] , server_reply[2000]; + + sock = socket(AF_INET , SOCK_STREAM , 0); + if (sock == -1) { + printf("could not create socket"); + } + server.sin_addr.s_addr = inet_addr(argv[1]); + server.sin_family = AF_INET; + server.sin_port = htons( port ); + + printf("connecting...\n"); + if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) { + perror("connect failed. Error"); + return 1; + } + printf("connected\n"); + + char *msg = "welcome to the machine!"; + // TX + if(send(sock, msg, strlen(msg), 0) < 0) { + printf("send failed"); + return 1; + } + else { + printf("sent message: %s\n", msg); + printf("len = %ld\n", strlen(msg)); + } + close(sock); + return 0; +} |
