当前位置:天才代写 > C++/C代写,c语言代写代考-100%安全,包过 > C作业代做 计算机作业代写 代写编程

C作业代做 计算机作业代写 代写编程

2023-03-20 16:47 星期一 所属: C++/C代写,c语言代写代考-100%安全,包过 浏览:385

C作业代做

Lab 11

C作业代做 The purpose of this lab is to practice using select to read from multiple inputs. This system call is usedin assignment 4.

Due Monday by 6:30pm   Points1
Lab 11: Select

Introduction

The purpose of this lab is to practice using select to read from multiple inputs. This system call is usedin assignment 4. lt is recommended that you use your solution to this lab as starting point forassignment 4.

Setup  C作业代做

Find the starter code in the Lab11 folder in your repository.
Like last week, you should change the port in the Makefile before doing anything else. Take the last fourdigits of your student number, and add a 5 in front. For example, if your student number is 998123456your port would be 53456. Using this base port, you may add 1 to it as necessary in order to use newports (for example, the fictitious student here could also use 53457, 53458, 53459, 53460). Sometimes.when you shutdown your server (e.g., to compile and run it again), the OS will not release the old portimmediately, so you may have to cycle through ports a bit.

An Echo System

Start by carefully reading through the starter code carefully making sure you understand what it alreadydoes.

Start with the chat_client.c code. This program creates a connection to a server. Then, it reads inputfrom the user, sends it to the server, and waits for a response which it displays back to the user onstandard out. lt strictly alternates these reads (from the keyboard and from the server).

What happens in chat_server.c ? lt accepts a connection from a client, Then, it waits for input from theuser and then echos it (it sends what is received right back). lt keeps information about multiple clients inan array and does this echoing operation independently with each of them. In other words, input fromone particular client is echoed only to that same client – not to all of the others. The server uses selectin a loop to process input from whichever client is talking without waiting for others.

The goal of the lab is to create a functioning chat system where the messages sent by one client aredelivered to all the other clients and participants are not required to talk in some pre-defined artificialturns, To accomplish this, you will need to change both the client and the server.

Task 1. Identify Yourself  C作业代做

Once we start broadcasting messages from the server, it will get confusing if we can’t identify who themessage comes from. The client asks the user for a username, reads the username from stdin , andwrites that username to the socket.

The server should be modified so that it reads the username after accepting the connection. But wecan’t just add the read call in the accept_connection function because the read might block. Rememberthat we should only call read on sockets where select has indicated that there is something ready toread. ln read_from we check to see if we have received a name yet (how can we tell?), and allocatememory for the user name field in the usernames struct and copy the name to the field for that client.

The username should be added to the table of struct sockname s it is managing. Then, whenever theserver echoes a message, it should prefix the message with username: , where “Username” is thatconnection’s name.

Task 2. Start Echoing   C作业代做

This is a quick task. Change the read_from function so that it broadcasts any message received to allconnected clients. Then, test by connecting more than one client to the server and making sure thatevery client receives any message that the other clients send. ltll be a bit awkward since our clients arereading from stdin before reading from the socket. You’ll have to hit Ente on the client that didn’t sendthe message to see what the other client has sent, and that will lead to the other clients receiving”empty” messages.

C作业代做
C作业代做

Task 3: Monitor stdin and the Socket in the Client

Take a look at how the server uses select . ln particular, look at the fd_set variables it is managing andhow it checks which file descriptor is ready for reading using FD_ISSE. Pay special attention to how thefdset used in the select call is reset for each new call. Make sure you understand how thechat_server.c starter code works before you try to use select in the client.

Your task is to update the client so it monitors just two file descriptors: the socket with the server and stdin. Whenever a message is received on either, your program should read it and pass it to the correctoutput stream.

Sample interactions  C作业代做

To help you better understand our chat system, we provide two sets of sample interactions. Thebehaviour of your program should be consistent with these interactions.

Please note that these interactions do not cover all possible scenarios and your program must take othersituations into account For example, the number of clients can vary, and clients can connect and disconnect at any time.

Interaction 1:

$ ./chat_client
Please enter a username: Karen
Hi
Karen: Hi
How is it going?
Karen: How is it going?
I'm glad it is Friday!
Karen: I'm glad it is Friday!
Bye
Karen: Bye
$ ./chat server
Accepted connection
Echoing message from client 4
Echoingmessagefrom client 4
Echoingmessagefrom client 4
Echoingclient 4messagefrom
Echoingmessage fromclient 4
^C

Interaction 2:

$ ./chat client
Please enter a username: Karen
Nathan: Hello
Hi!
Karen: Hi!
How are you?
Karen: How are you?
Nathan: I'm fine. I hope you are well.
It's almost time for class.
Karen: It's almost time for class.
Nathan: See you later
Bye
Karen: Bye
$ ./chat client
Please enter a username: Nathan
Hello
Nathan: Hello
Karen: Hi!
Karen: How are you?
I'm fine. I hope you are well.
Nathan: I'm fine. I hope you are wel1.
Karen: It's almost time for class.
See you later
Nathan: See you later
Karen: Bye
$ ./chat_server
Accepted connection
Echoing message from client 4Accepted connection
Echoing message from client 5
Echoing message fromclient 5
Echoing message from client 4
Echoing message fromclient 4
Echoing message fromclient 5
Echoing message from client 4
Echoing message fromclient 5
Echoing message from client 4
^C

MarkUs checker: only checks compilation   C作业代做

We have provided a checker program for Lab 11 on MarkUs, but it only checks that your submissioncompiles. It does not check the correctness of your program.

Submission

Submit your final chat client.c and chat_server.c files to MarkUs under the Lab11 folder in yourrepository.
Congratulations! You’ve finished the last lab of the course. Good luck with the last assignment!

 

C作业代做
C作业代做

更多代写:管理学代写范文  roctoru review作弊  代修商科网课   代写Essay英文  代写paper  代写英语毕业论文

合作平台:essay代写 论文代写 写手招聘 英国留学生代写

 

天才代写-代写联系方式