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
Instructions:Select the correct answer.
Luba_88 [7]
<span>A.) system administrator

Hope that helps</span>
8 0
3 years ago
Read 2 more answers
Print Job Cost Calculator (10 points)
Ad libitum [116K]

Answer: Provided in the explanation section

Explanation:

Provided is the code  to run this program

Source Code:

import java.util.Scanner;

class PrintJobCost

{

  public static void main(String[] args) {

      Scanner input=new Scanner(System.in);

      System.out.print("Enter print job info:");

      String info=input.nextLine();

      String size="",type="";

      int count=0,i=0,len=info.length();

      double cost=0.0;

      while(info.charAt(i)!=' '){

          size=size+info.charAt(i);  

          i++;

      }

      i++;

      while(info.charAt(i)!=' '){

          type=type+info.charAt(i);

          i++;

      }

      i++;

      while(i<len){

          count=count*10+Integer.parseInt(String.valueOf(info.charAt(i)));

          i++;

      }

      if(size.equals("Letter"))

          cost=cost+0.05;

      else if(size.equals("Legal"))

          cost=cost+0.06;

      else if(size.equals("A4"))

          cost=cost+0.055;

      else if(size.equals("A5"))

          cost=cost+0.04;

      if(type.equals("Grayscale"))

          cost=cost+0.01;

      else if(type.equals("Colored"))

          cost=cost+0.10;

      cost=cost*count;

      System.out.printf("print job Cost:$ %.2f\n",cost);

  }

}

cheers i hope this helped !!!

8 0
3 years ago
A queue processes elements in a _____ manner. <br> a. filo <br> b. lifo <br> c. lilo <br> d. fifo
sladkih [1.3K]

A queue processes elements in a <u> fifo</u> manner.

<h3>What is the rule that each stack and queue are understood by?</h3>

The rule used for a queue is to permanently remove the item that has been in the collection the most amount of time.

This policy is known as first-in-first-out or FIFO. The rule used for a stack is to always remove the item that has been in the collection the least amount of time.

<h3>What is queue how it is distinct from stack and how is it implemented?</h3>

The primary difference between Stack and Queue Data Structures is that Stack pursues LIFO while Queue follows FIFO data structure type. LIFO guides to Last In First Out. It means that when we put data in a Pile, it processes the last entry first. Conversely, FIFO guides to First In First Out

To learn more about FIFO,  refer

brainly.com/question/27952133

#SPJ4

3 0
1 year ago
Are there any tips or helpful advice for people who want to learn Photoshop?
stepan [7]

I feel like it is best to mess with it some with pictures you don't care about so you can see what would and what doesn't. that is how my sister did it and she take some grad pics. there are probably classes to

3 0
3 years ago
The first thing you must consider in any type of communication is ______.
Wittaler [7]
As for this problem together with the options as answers presented with it, the most probable and the most likely answer would be C. the purpose of the communication.

The first thing you must consider in any type of communication is the purpose of the communication itself. Determining the purpose behind the communication would, in turn, pave way to determining the other things that is needed to be determined such as the type of communication, the style of communication, the timing of the communication, and so on and so forth.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which is the best description of a hierarchical report?
    13·1 answer
  • Software that manages and supports the resources of a computer is known as?
    10·1 answer
  • What is the simplest way to convert a decimal number in a binar one in c++?
    8·1 answer
  • If 10 ft lb of torque is applied at gear A, then what is the output torque at gear D?
    15·1 answer
  • The 7-bit ASCII code for the character ‘&amp;’ is: 0100110 An odd parity check bit is now added to this code so 8 bits are trans
    5·1 answer
  • As a general rule, what is the size of a brochure?
    11·1 answer
  • ______ behavior expected from every professional​
    12·1 answer
  • What is storage unit in computer and five examples of storage units.<br>​
    5·2 answers
  • assuming the default gateway is connected to the internet, what type of internet access would this server have?
    14·1 answer
  • PLEASE HELP ME
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!