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
Use input() function to take 4 user inputs as variables and choose at least 2 ways to print out the following statements. You ca
taurus [48]

Answer:

statements = tuple(input("Enter four statements separated by comma: ").split(","))

st1, st2, st3, st4 = statements

#print with:

print(f"{st1}, {st2}, {st3}, {st4}")

# or:

print("{}, {}, {}, {}".format(st1, st2, st3, st4))

Explanation:

The input function in python is used to prompt for user input. It returns a string. The code above splits the string of the input function and converts it to a tuple, which is unpacked in four variables st1, st2, st3, and st4.

The variables can be printed out as strings directly or by using the "f" keyword or the format function.

6 0
2 years ago
Which of the following projections is typically used for navigation?
kondor19780726 [428]
D. orthographic is the answer

5 0
3 years ago
Read 2 more answers
Given these 4 bit binary one's complement numbers: 1110 and1100, what would be a correct 4 bit binary one's complement resultof
Kruka [31]

Answer:

b. 1010

Explanation:

As per question,two 4-bit binary one's complement numbers are given-

   1110 and 1100

and we have to find the addition of them,

In <u>1</u>11<u>0</u>, the MSB(most significant bit) is 1 and LSB(least signifacnt bit) is 0,So we will start addition from LSB i.e 0.

In <u>1</u>10<u>0</u>, the MSB(most significant bit) is 1 and LSB(least signifacnt bit) is 0,So we will start addition from LSB i.e 0.

Starting from LSB TO MSB-

          Add 0 of 111<u>0</u> with 0 of 110<u>0</u>

               we will get 0, with no carry.

then check for the left of the previous  

        Add 1 of 11<u>1</u>0 with 0 of 11<u>0</u>0

              we will get 1, with no carry.

then check for the left of the previous  

        Add 1 of 1<u>1</u>10 with 1 of 1<u>1</u>00

              we will get 0, with 1 carry.

This carry is shifted to the left we will add it in addition of the two.

        Add 1 of <u>1</u>110 , 1 of <u>1</u>100 and the left carry i.e-1.

              we will get 1, with 1 carry.

So, finally we get 1 |1010, we will eliminate carry.

           1010 will be the answer

5 0
3 years ago
What is the difference between ""cracking"" a code and ""decrypting"" a message?
Brut [27]

Answer:

Cracking a code is when you attempt to decode a secret message without knowing all the specifics of the cipher and decryption is when you already know the key and are trying to reverse the process of encryption.

Explanation:

3 0
3 years ago
Which are categories in the Number tab of the Format Cells dialog box. Check all that apply
jok3333 [9.3K]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is, you can find all categories except Formula in the Number tab of the Format Cells dialog box.

You can find the categories in the Format Cells dialog box as listed below:

  • General
  • Number
  • Currency
  • Accounting
  • Date
  • Time
  • Percentage
  • Fraction
  • Scientific
  • Text
  • Special and
  • Custom.

As you see in the above list, there is no Formula category given the Number tab of the Format Cell dialog box. So the correct options are:

  1. General
  2. Number
  3. Currency
  4. Date
  5. Time
  6. Percentage

5 0
3 years ago
Other questions:
  • I plugged my phone up into a charger, the charger sparked and i unplugged my phone and now it wont charge at all, does anyone kn
    13·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    7·1 answer
  • What is the main role of LDAP?
    14·1 answer
  • . Select the advantages of RAID-5 relative to other RAID schemes. (MAY SELECT MULTIPLE)
    7·1 answer
  • Which steps will create a new blank word document
    9·1 answer
  • If I could make a Short Film on any topic it would be...how could that film change the world?
    9·1 answer
  • What statement describes the last step in evaluating<br> information?
    10·1 answer
  • You can customize backdrops in Scratch, adding text or freestyle drawings over the initial image
    12·1 answer
  • ________ software consists of operating systems, utilities, device drivers, and language translators.
    7·1 answer
  • Get ready to be the Quizmaster! You are going to design your own Python game show in the style of a quiz.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!