mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 01:13:23 +00:00
Format code automatically for regression tests
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
60cd65d837
commit
82de200d03
@ -8,37 +8,39 @@
|
||||
|
||||
#define PORT 8080
|
||||
|
||||
int main() {
|
||||
int sock = 0, valread;
|
||||
struct sockaddr_in serv_addr;
|
||||
char *hello = "Hello from client";
|
||||
char buffer[1024] = {0};
|
||||
int main()
|
||||
{
|
||||
int sock = 0, valread;
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
// 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");
|
||||
valread = read(sock, buffer, 1024);
|
||||
printf("Server: %s\n", buffer);
|
||||
return 0;
|
||||
// Send message to the server and receive the reply
|
||||
send(sock, hello, strlen(hello), 0);
|
||||
printf("Hello message sent\n");
|
||||
valread = read(sock, buffer, 1024);
|
||||
printf("Server: %s\n", buffer);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user