C语言代写 | TCP网络编程| Network Computing Assignment 3 CSCI 3171 Network Computing Winter 2019



Design a client-server application using TCP sockets, where you use the client to play a game of “Rock-Paper-Scissors” with the server.

You may complete this assignment in groups of 2 students. Only one submission per group is required.


Rock-Paper-Scissors game:
This is a game usually played between two people using their hand. Each player simultaneously forms one of three shapes – Closed fist for a rock, open palm for a paper and a V-shape using two fingers for a scissor. The game is decided as follows:

  • Rock beats scissors,
  • Scissors beats paper, and
  • Paper beats rock

This is summarized in the figure on the right.

Your Task:

you will write simple client-server application(s) in which the client acts as Player 1 and the server acts as Player 2. The protocol between the client and server should be as follows:

  • The server program is started on a user-defined port.
  • The client program is started and connects to the server using the server IP and port number provided on the command line.
  • The client asks the user for input. The input may either be R (for Rock), P (for Paper) or S (for Scissors). Any other input should result in an error message, asking the user to try again.
  • The user’s input is sent to the server via the connected socket.
  • The server (acting as Player 2) must decide on any one of R, P or S. How the server decides is completely up to you. For a fair game for example, you may use a random approach to decide between choosing R, P or S for the server.
  • The server reads the user’s input from the client socket, evaluates the outcome (Player 1 wins, Player 2 wins or a tied game), displays each players’ choice and result of the game, and also sends this information (i.e. Client’s choice, Server’s choice and the result of the game) back to the client.
  • The client should display the server’s reply (i.e. Client’s choice, Server’s choice and the result of the game) to the user.
  • The client should give the user an option to try again or quit.

Socket Programming:

The steps for creating a socket on the client side are:

  • Create a socket with the socket() system call
  • Connect the socket to the address of the server using the connect() system call
  • Send and receive data. There are several ways to do this. You may use the read() and write() system calls, or the send() and recv() system calls

The steps involved in establishing a socket on the server side are as follows:

  • Create a socket with the socket() system call
  • Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine
  • Listen for connections with the listen() system call
  • Accept a connection with the accept() system call. This call typically blocks until a client connects with the server
  • Send and receive data

Additional Help and Reading:

Following are some helpful tutorials on socket programming using TCP including code samples. Feel free to study and understand any or all of these before starting on your assignment.

• http://www.linuxhowtos.org/C_C++/socket.htm
• https://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C
• http://www.csd.uoc.gr/~hy556/material/tutorials/cs556-3rd-tutorial.pdf

Note: Above references are for understanding how socket programming works. You are not allowed to copy any code from the above sources.


This assignment can be done individually, or in groups of 2. In case of groups, only one submission per group is required.
Upload a single zip file containing:

  1. your code (consisting of your c or c++ file(s)),
  2. an image file (.jpg or .png) showing a screen capture of your program in action, and
  3. a readme.txt file containing names of the group members, specific contribution by each team member (if group of 2) and instructions to compile and run your program including the compilation string (and the execution string if applicable). to the Assignment 3 dropbox on Brightspace. Do not submit the executable.


Friday, 01-March-2019, 11:59PM


  • Code for both the client and the server compiles using gcc on Bluenose. Assignment instructions are properly followed. (Note that you may decide to build a single app with an option to run it as either a client or a server.)
    • You will get a zero in this assignment if your code does not compile on bluenose.
    • Also note that marks will be deducted for any warnings generated during compilation.
  • Client can connect to the server running on either a local or a remote host. Be sure to test your client’s connectivity by connecting to the server running on a different machine. [4]
  • Client’s message is received by the server, server correctly finds the outcome (i.e. Win, Loss or Tie) and displays this information. [6]
  • Server’s message is received by the client and the client can display this information (i.e. the choices and result) to the user. [6]
  • Code is well written, properly formatted and commented. Basic error handling is done. [2]
  • Readme.txt file is provided with the correct compilation string and specific contribution made by group members (if applicable). [2]

    [Note: You do not need to write a multi-threaded server. Connecting a single client at a time is enough]


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx