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
Apple Final Cut Pro is a digital video editing program that is available for Macs with OS X version 10.4 or later.
aniked [119]
That's actually true lol

3 0
3 years ago
Read 2 more answers
The fourth generation of computers was marked by the introduction of ____.
Mila [183]
<span>The fourth generation of computers was marked by the introduction of microprocessors. </span>
6 0
3 years ago
To resize an embedded chart, ____. select one:
Mrrafil [7]
I think its ' D ' ,You can use both A and B
5 0
3 years ago
The Internet is a hierarchical structure linking different levels of service providers whose millions of devices supply all the
STatiana [176]

Answer:

Explanation:

These are the three diffrent levels listed below;

1) NSP (National Service Provider)

2) RSP (Regional Service Provider)

3) ISP (Internet Service Provider)

4 0
3 years ago
Which of the following statements is FALSE?
ICE Princess25 [194]

Complicated faces and shapes are more easily remembered in games.

Thus, the correct option is C.

<h3>What is a game?</h3>

A game is a systematic kind of play that is typically done for enjoyment or fun, though it can also be used as a teaching tool.

A lot of games are also regarded as works of art. Sometimes people play games only for fun, while other times they play for recognition or reward.

Every game has participants, goals, a set of rules, and feedback. A game is what these things put together to make it.

A game's objectives, rules, difficulty level, and interactivity are crucial elements.

There are several reasons why people engage in mind games, but the main one is typically to exert control or authority over another individual.

Learn more about the games, here:

brainly.com/question/3863314

#SPJ1

3 0
1 year ago
Other questions:
  • Which information technology job has the lowest predicted 10-year growth? computer programmer software developer computer suppor
    13·1 answer
  • A technician is troubleshooting a small network with cable Internet service in which a user is receiving a message in her web br
    15·1 answer
  • To quickly modify fonts, colors, and effects on a slide, a user can modify the _____. (Microsoft PowerPoint)
    11·1 answer
  • Why does air have weight?
    6·2 answers
  • One or more access points positioned on a ceiling, wall, or other strategic spot in a public place to provide maximum wireless c
    9·1 answer
  • A manager would like information on the knowledge base searches conducted by customers and call center agents. Which two metrics
    10·1 answer
  • One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input
    12·1 answer
  • Write a program that removes all non-alphabetic characters from the given input.
    7·1 answer
  • Many large companies use the word(s), _____, to refer to the huge network of computers that meets their diverse computing needs.
    12·1 answer
  • try the following code to see a nullpointer error (if you don’t see the error because of the autograding, you can copy it into t
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!