mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
Rename regression to test
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
5eefd600cc
commit
f675552c5a
46
test/apps/network/tcp_client.c
Normal file
46
test/apps/network/tcp_client.c
Normal file
@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define PORT 8080
|
||||
|
||||
int main()
|
||||
{
|
||||
int sock = 0;
|
||||
struct sockaddr_in serv_addr;
|
||||
char *hello = "Hello from client";
|
||||
char buffer[1024] = { 0 };
|
||||
|
||||
// Create socket
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
printf("\n Socket creation error \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_port = htons(PORT);
|
||||
|
||||
// Convert IPv4 address from text to binary form
|
||||
if (inet_pton(AF_INET, "127.0.0.1", &(serv_addr.sin_addr)) <= 0) {
|
||||
printf("\n Invalid address/ Address not supported \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Connect to the server
|
||||
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <
|
||||
0) {
|
||||
printf("\n Connection Failed \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Send message to the server and receive the reply
|
||||
send(sock, hello, strlen(hello), 0);
|
||||
printf("Hello message sent\n");
|
||||
read(sock, buffer, 1024);
|
||||
printf("Server: %s\n", buffer);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user