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

代做C语言作业 计算机作业代写

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

代做C语言作业

A4 – Sockets and Select

代做C语言作业 This makes it possible torun several auction server programs on the same machine at the same time, because each needs tolisten on a different port.

Introduction

In this assignment you will be writing a client that will connect to multiple servers and will allow the useito enter bids for the items on auction by these servers. Each auction server offers one item for biddingand accepts bids on that item from multiple clients for a limited time period.

Auction Server  代做C语言作业

You should not change the auction server program. The auction server take the following arguments:

  • -v- lf this argument is present the auction server will print more information
  • -p <port> You can pass a port number for the auction server to listen on. This makes it possible torun several auction server programs on the same machine at the same time, because each needs tolisten on a different port.
  • -t <timeout> – The timeout option is in minutes and specifies the length of the auction. lf thisargument is omitted, the auction server will run forever.
  • item – The final argument is not optional. lt is a single word that describes the item being auctioned    代做C语言作业

Note: Since you are running processes that may potentially run for a long time, you it is important tocheck periodically and kill processes that you aren’t actively using. You can do this using the ki11a11command. For example killal] auction_server will kill all the auction server processes that you own.

The auction server istens for requests of the following format:

  • The first message from a client will contain the name of the client. Upon receiving a name, theauction server will store the name in the array of users.
  • Subsequent messages from a client will be a single number sent as a string representing a bid.Upon receiving a bid, the server will check to see if the new bid is higher than the highest bid so far.if it is, it will update the highest bid, and will broadcast the new bid to all current clients.

ºThe message sent to each client has the format:0bidsecondsremainine

When the timer runs out, the server will send a message to all clients of the form:

"Auction closed: <name> wins with a bid of <bid value>\r\n"
代做C语言作业
代做C语言作业

Auction Client

Your task is to complete the auction client program. The client program takes no command linearguments. lt reads all of its commands from stdin. It first prompts the user to enter a user name, andthen displays a menu of commands. lt then enters an infinite loop where it reads commands fromstandard input, and receives messages from any auction servers it is connected to. There are four valid commands:
1.show
The show command will call print auctions() to print the current auction data to stdout.
2. add <server address> <port number>

The server address and port number identfy an auction server to connect to. This command will calladd server to connect to a new server, and write the user name to the server. lt will also record the newconnection the auctions array.  代做C语言作业

3.bid <item index> <bid value>

This command sends a bid to the auction server store at index in auction data array. The value of thebid does not need to be checked in the client, and is sent as a string to the server.

4.quit

The client simply closes its open sockets and exits.

The client must also handle any messages coming from the auction servers with which it is connected.These messages might be an update to the highest bid (due to a bid sent by this client or another client),or a message closing the auction.

The client program must use select so that the client program will not be blocked in a read call to stdin orto another client when a new message is available. There is no timeout for the client.

Makefile and Port Number  代做C语言作业

To avoid port conflicts when testing your programs on teach.cs, you will use PORT (see below) to specifya port number. Select that number using the same algorithm we used for lab 10: take the last four digitsof your student number, and add a 5 in front. For example, if your student number is 1008123456, youlport would be 53456. Using this base port, you may add 1 to it as necessary in order to use new portsfor example, the fictitious student here could also use 53457, 53458, 53459, 53460). Sometimes, whenyou shutdown your server (e.g. to compile and run it again), the OS wil not release the old portimmediately, so you may have to cycle through ports a bit.

ln auction_server.c , replace 30000 with the port number on which the server will expect connections(this is the port based on your student number):

#ifndef PORT
#define PORT 30000
#endif

Then, in Makefile , replace x with your student number port plus 1:

PORT= X;

Now, if you type make PORT-53456 the program will be compiled with PORT defined as 53456 . lf you typejust make , PORT will be set to y as defined in the makefile. Finally, if you use gcc directly and do notuse –D to supply a port number, it will still have the x value from your source code file. This method ofsetting a port value gives the server program a default port to listen on if the -p option is not provided.Read the Makefile. lt’s also useful for you to know how to use D to define macros at command line.)

Strategy

lt is strongly recommended that you complete lab 11 before starting this assignment. You will beable to use your work in lab 11 as a starting point for this assignment.

Read the starter code for auction client carefully! There are multiple helper functions written for you.  代做C语言作业

The only system call that should block in the client is select.

The primary task in this assignment is to manage the state of multiple server connections and stdin.

A shell script runservers is provided in the starter code, t starts 5 auction servers on consecutivelynumbered ports to make it easier to test.

System calls must be checked for error, but you do not need to worry about handling different kindsof bad input.

Submit  代做C语言作业

Commit and push auction_client.c to the repository. Please do all of your coding in auction_client.c.

 

代做C语言作业
代做C语言作业

更多代写:医学考试代考  网考代考  艺术Midterm代考  英国essay代写格式  fin金融学论文写作  cs exam代考

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

 

天才代写-代写联系方式