1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rus_ich [418]
3 years ago
12

A haiku is a three-line poem in which the first line contains five syllables, the second line contains seven syllables, and the

third line contains five syllables. Write a haiku server that listens to port 5755. When a client connects to this port the server responds with a haiku; written in C language. Should only be a few lines of code.
Computers and Technology
1 answer:
tankabanditka [31]3 years ago
4 0

Answer:

Files :

server.c

client.c

Haiku msg : ( source internet )

Birds fly through the wind

The wind blows through the blue sky

Winds of change grow close

Explanation:

server.c

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/socket.h>

#include <netinet/in.h>

// Here we've defined the PORT

#define PORT 5755

// This a out haiku_msg

const char haiku_msg[] = "Birds fly through the wind\nThe wind blows through the blue sky\nWinds of change grow close";

int main()

{

int server_fd, new_socket;

struct sockaddr_in address;

int addrlen = sizeof(address);

// Creating socket file descriptor

if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {

perror("socket failed");

exit(EXIT_FAILURE);

}

address.sin_family = AF_INET;

address.sin_addr.s_addr = INADDR_ANY;

address.sin_port = htons(PORT);

if (bind(server_fd, (struct sockaddr*)&address, sizeof(address)) < 0) {

perror("bind failed");

exit(EXIT_FAILURE);

}

printf("haiku server started...\n\n");

if (listen(server_fd, 5) < 0) {

perror("listen");

exit(EXIT_FAILURE);

}

if ((new_socket = accept(server_fd, (struct sockaddr*)&address, (socklen_t*)&addrlen)) < 0) {

perror("accept");

exit(EXIT_FAILURE);

}

printf("\nClient connected to haiku server.\nsending msg.\n");

send(new_socket, haiku_msg, strlen(haiku_msg), 0);

printf("haiku sent to client.\n\n");

return 0;

}

client.c

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <arpa/inet.h>

#include <sys/socket.h>

#include <netinet/in.h>

// Here we have defined the PORT

#define PORT 5755

int main()

{

char buffer[1024] = "";

struct sockaddr_in address;

struct sockaddr_in serv_addr;

int sock = 0;

if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)

{

printf("\n Socket creation error \n");

return -1;

}

memset(&serv_addr, '0', sizeof(serv_addr));

serv_addr.sin_family = AF_INET;

serv_addr.sin_port = htons(PORT);

// Convert IPv4 and IPv6 addresses from text to binary form

if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)

{

printf("\nInvalid address/ Address not supported \n");

return -1;

}

if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)

{

printf("\nConnection Failed \n");

return -1;

}

read( sock , buffer, 1024);

printf("\nMessage from server : \n%s\n\n",buffer );

return 0;

}

You might be interested in
Why should spain go to Africa ​
uysha [10]

Answer:

to learn about their cultural heritage and historical significance

3 0
3 years ago
What is another word for: a location in memory that contains a value? A. integer B. Boolean C. variable D. float PLEASE HELP URG
german

Answer:

A

Explanation:

Integer because it contains digits that can undergo calculation within the memory

5 0
2 years ago
Which of the following would a high school graduate interested in the performing arts most likely do after graduation?
pashok25 [27]

Answer: College

Explanation: I got it right on my quiz

3 0
3 years ago
Choose all items that represent HTML characteristics.
hram777 [196]

Answer:

A,C,D,E are the answers at least on the test i took

Explanation:

3 0
3 years ago
Read 2 more answers
what is one example of the decomposers taking from the ecosystem and one of them giving to the ecosystem
adelina 88 [10]
Like when a seed drops on the ground, and a bee come to take some honey. It sticks to the bee and where the bee goes, the bee will rub it off and the seed will start to grow.
8 0
2 years ago
Other questions:
  • Which of the following would an interactive media proffessional must likely need
    9·1 answer
  • Write a program called DeliveryCharges for the package delivery service in Exercise 4. The program should again use an array tha
    9·1 answer
  • .What particular skills does a team leader need in addition to the other skills needed by any team member. (choose all that appl
    6·1 answer
  • How to write email abut new home your friend ​
    14·1 answer
  • What is the definition of the word uproot?
    15·1 answer
  • The _____ feature will mark all changes made to a document for others to review at a later time.
    13·1 answer
  • Ajdbksjdnksnsd helppp​
    11·1 answer
  • Need help with this, will give brainliest
    15·1 answer
  • In the following shell scripting extract, the initial values of variables s, c and p are 0, 1, 1 respectively. What will be the
    6·1 answer
  • Which window would show you bindings for local area connection 2?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!