socket-client: Send a user-provided message to the server
This commit is contained in:
parent
187f0ff83e
commit
8475a3aad9
@ -1,11 +1,20 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
StringView message;
|
||||
|
||||
os::ArgumentParser parser;
|
||||
parser.add_description("A UNIX domain socket client, to test said sockets.");
|
||||
parser.add_system_program_info("socket-client"_sv);
|
||||
parser.add_positional_argument(message, "message"_sv, "exit"_sv);
|
||||
parser.parse(argc, argv);
|
||||
|
||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
{
|
||||
@ -31,8 +40,7 @@ int main()
|
||||
printf("Message from server: %s\n", buf);
|
||||
}
|
||||
|
||||
const char* message = "EXIT";
|
||||
write(sockfd, message, strlen(message));
|
||||
write(sockfd, message.chars(), message.length());
|
||||
|
||||
close(sockfd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user