TCP, UDP network programming job generation, write C language TCP program network programming using C

Source: Internet
Author: User
Tags alphanumeric characters

TCP, UDP network programming job generation, write C language TCP program
Network Programming using C
Overview
? This homework was due by 11:59:59 PM on Thursday, April 26, 2018.
? This homework would count as 8% of your final course grade.
? This homework was to be completed individually. Share your code with anyone else.
? You must use C for this homework assignment, and your code must successfully compile
Via GCC with absolutely no warning messages if the-wall (i.e., warn all) compiler option
is used. We'll also Use-werror, which'll treat all warnings as critical errors.
? Your code must successfully compile and run on Submitty, which uses Ubuntu v16.04.3 LTS.
Note that the GCC compiler is version 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5).
? If you decide to use a multi-threaded approach, to compile your code, Use-pthread to include
The Pthread library.
Homework Specifications
In this fourth and final homework assignment, you'll use the C to write server code to implement
A chat server using sockets. Clients'll be able to send and receive short text messages from one
another. Further, clients'll also be able to send and receive files, including both text and binary
Files (e.g., images). Note that all communication between clients must is sent via your server.
Clients communicate with your server via TCP or UDP. For TCP, clients connect via a specific TCP
Port number (i.e., the listener port); This TCP port number was the first command-line argument to
Your server. For UDP, Clients send datagram (s) to a specific UDP port number; This UDP port
Number is the second command-line argument to your server (and could be the same port number
As the TCP listener).
Your server must not is a single-threaded iterative server. Instead, your server must use either
Multiple threads or multiple child processes to handle TCP connections. Your choice! Further, to
Support both TCP and UDP at the same time, you must use the Select () system call to poll for
Incoming TCP connections and UDP datagrams.
As with previous assignments, your server must is parallelized to the extent possible. As such, be
Sure handle all potential synchronization issues.
Note that your server must support clients implemented in any language (e.g., Java, C, Python,
Fortran, etc.); Therefore, only handle streams of bytes as opposed to language-specific structures.
And though you'll only submit your server code for this assignment, plan to create one or more
Test clients. Test clients is not being provided, but feel free to share test clients with others via
Piazza. Also Note that you should the use of Netcat to test your server; Do is use Telnet.
Supporting TCP and UDP
To provide flexibility to clients, clients can either establish a connection via TCP or simply
Send/receive datagrams via UDP. Your server must support at least concurrently connected
Clients (i.e., TCP connections, with all connection corresponding to a child thread or a child
Process). Overall, your server must support at least-active users at any given time.
For TCP, the use a dedicated the child process or the child thread to the handle each TCP connection. In other
Words, after the accept () call, immediately create a child process or child thread to handle that
connection, thereby enabling the parent process or thread to loop back around and call Select ()
Again.
Since UDP is connectionless, for UDP, use an iterative approach (i.e., handle incoming UDP datagrams
The parent process or main thread, then loop back around to the Select () system call).
Application-layer Protocol
The Application-layer protocol between client and server is a line-based protocol. Streams of bytes
(i.e., characters) is transmitted between clients and your server. Note that all commands is
specified in Upper-case and end with a newline (' \ n ') character. When the server
Receives a request, it responds with either a three-byte "ok\n" response or an error. When an error
Occurs, the server must respond with:
ERROR <error-message>\n
The For any error message is not specified below, and use a short human-readable description matching the
Simple format shown above. Expect clients to display these error messages directly to users.
LOGIN
Regardless of whether a client uses TCP or UDP, a user must first log in (though authentication are
Not required). A user identifies itself as follows:
LOGIN <userid>
Note that a valid <userid> was a string of alphanumeric characters with a length in the range [3,20].
Upon receiving a LOGIN request, if successful, the server responds by sending the Three-byte "ok\n"
String. If instead the given <userid> is already connected via TCP, the server responds with an
<error-message> of "Already connected" (only for TCP). Otherwise, if <userid> is invalid, the
Server responds with a <error-message> of "Invalid userid" (for TCP and UDP).
2
W.H.O.
A user may send a WHO request to obtain a list of all users currently active within the chat server.
When your server receives this request, in addition to sending ' ok\n ' to the client, the response
Should consist of a ascii-based sorted list of all users, with the users delimited by newline (' \ n ')
Characters.
As an example, the server may respond with the following:
Ok\nmorty\nrick\nshirley\nemacs\vi\n
LOGOUT
A user may send a LOGOUT request to ensure the server marks the user as being completely logged
Out and inactive. Note that this is recommended and not required for TCP, since the client can
Simply close its connection to indicate it was logging out.
For UDP, if a LOGOUT are not sent, the given user was assumed to still being logged in until a new LOGIN
Request is received for that given user.
When a LOGOUT command was sent, the server is required to send a "ok\n" response.
SEND
A user may attempt to send a private message to another user via the Send command. The required
Format of the SEND command is as follows:
SEND <recipient-userid> <msglen> <message>
To is a valid SEND request, the <recipient-userid> must be a currently active user and the
<msglen> (i.e., length of the <message> portion) must be a integer in the range [1,994].
Note that the <message> can contain any bytes whatsoever. Assume that number of
Bytes'll always match the given <msglen> value.
If the request is valid, the server responds by sending an "ok\n" response. Further, the server
Attempts to send the message to the <recipient-userid> by sending either a datagram (UDP) or
Packet (TCP) using the following format:
From <sender-userid> <msglen> <message>
If the request is invalid, send the appropriate error message from among the following:
? "Unknown userid"
? "Invalid Msglen"
? "Invalid SEND format"
3
Broadcast
If a user wishes to send a message to any active users, the broadcast command can be used. The
Format of this command is as follows:
Broadcast <msglen> <message>
The <msglen> and <message> parameters match that of the SEND command above.
SHARE
If a user wishes to share a file with another user, the share command was sent by the client by first
Sending the command request as follows:
SHARE <recipient-userid> <filelen>
After receiving the "ok\n" response, the client sends the file (of length <filelen> bytes) in 1024-byte
Chunks (i.e., send () or sendto () calls using a 1024-byte buffer). Each chunk must is acknowledged
By the server with a Three-byte "ok\n" response. The last chunk sent can is less than
1024x768 bytes.
The server subsequently sends the SHARE command to the <recipient-userid> in the same manner,
Though the recipient client does not send acknowledgement "ok\n" messages
Server. Further, as with the SEND command, the format of the SHARE command sent to the
<recipient-userid> is as follows:
SHARE <sender-userid> <filelen>
Note that the SHARE command was only available if both users (i.e., sender and recipient) are connected
Via TCP. If This isn't the case, send the appropriate error message from among the following:
? "SHARE not supported over UDP"
? "SHARE not supported because recipient is using UDP"
Text versus Binary Files
All regular files must is supported, meaning that both text and binary (e.g., image) files must be
Supported. To achieve this, being sure you don't assume that files consist of strings; In other words,
Do not use String functions this rely on the ' character '. Instead, rely on specific byte counts.
As noted above, you can assume that the correct number of bytes would be sent and received by
Client and server. In practice, it's not a safe assumption, but it should greatly simplify your
implementation.
4
Required Output
Your server is required to output one or more lines describing each request that it receives. Required
Output is illustrated in the example below.
Since you is required to use either child processes or child threads, the child IDs shown in the
Examples is either thread IDs or process IDs. And as per usual, output lines may be interleaved
As multiple clients interact with the server simultaneously.
bash$./a.out 9876 9889
main:started Server
Main:listening for TCP connections on port:9876
Main:listening for UDP datagrams on port:9889
...
MAIN:RCVD incoming UDP datagram from: <client-IP-address>
MAIN:RCVD LOGIN Request for UserID Rick
...
MAIN:RCVD incoming TCP connection from: <client-IP-address>
Child 13455:RCVD LOGIN request for UserID Morty
Child 13455:RCVD who request
Child 13455:RCVD SEND request to UserID Rick
Child 13455:RCVD SEND request to UserID Summer
Child 13455:sent ERROR (Unknown userid)
Child 13455:RCVD who request
Child 13455:RCVD SHARE Request
Child 13455:RCVD LOGOUT Request
Child 13455:client Disconnected
...
MAIN:RCVD incoming TCP connection from: <client-IP-address>
Child 19232:RCVD LOGIN request for UserID Rick
Child 19232:RCVD who request
Child 19232:RCVD SEND request to UserID Rick
Child 19232:RCVD SEND request to UserID Rick
Child 19232:RCVD SEND request to UserID Morty
MAIN:RCVD incoming UDP datagram from: <client-IP-address>
MAIN:RCVD LOGIN Request for UserID Rick
Main:sent ERROR (already connected)
Child 19232:RCVD SEND request to UserID Morty
Child 19232:RCVD Broadcast Request
Child 19232:client Disconnected
...
Note that the required output above certainly differs from the specific data sent and received via the
Application-layer protocol. On Submitty, test clients'll connect to your server and test whether
You are correctly implemented all aspects of the Application-layer protocol.
5
Handling System Call Errors
In general, if a system call fails, use Perror () to display the appropriate error message on stderr,
Then exit the program and return exit_failure. If a system or library call does not set the
Global errno, use fprintf () instead of perror () to write a error message to stderr. See the
Various examples on the course website and corresponding mans pages.
Error messages must is one line only and use one of the appropriate formats shown below:
Main:error <error-text-here>
Pre
Child 17552:error <error-text-here>
Submission Instructions
To submit your assignment (and also perform final testing of your code), please use Submitty, the
Homework Submission server. The specific URL is on the course website. As described above, please
Only submit server code. Don't submit any client code.
Note that this assignment would be available on Submitty a few days before the due date. Please
Don't ask on the Piazza when Submitty'll be available, as you should perform adequate testing on
Your own Ubuntu platform.
That's said, to make sure. Your program does execute properly everywhere, including Submitty,
Use the techniques below.
First, as discussed in class (on 1/18), output to standard output (stdout) is buffered. To ensure
Buffered output is properly flushed to a file for grading in Submitty, use Fflush () after every set
of printf () statements, as follows:
printf (...); /* Print something out to stdout */
Fflush (stdout); /* Make sure, the output is sent to a */
/* Redirected output file, if specified */
Second, also discussed in class (on 1/18), with the debug_mode technique to make sure
Submit any debugging code. Here are an example:
#ifdef Debug_mode
printf ("The value of X is%d\n", x);
printf ("The value of Q is%d\n", q);
printf ("Why are my program crashing here?!");
Fflush (stdout);
#endif
and to compile the "debug" mode, use THE-D flag as follows:
bash$ gcc-wall-werror-d Debug_mode Homework4.c-pthread
Http://www.6daixie.com/contents/19/1369.html

The core staff of the team mainly include Silicon Valley engineers, bat front-line engineers, domestic TOP5 master, PhD students, proficient in German English! Our main business scope is to do programming big homework, curriculum design and so on.

Our Direction field: Window Programming numerical algorithm AI Artificial Intelligence financial statistical Metrology analysis Big Data network programming Web programming Communication Programming game Programming Multimedia Linux plug-in programming API image processing embedded/Microcontroller database programming console process and thread Network security assembly language Hardware programming software Design Engineering Standard Rules. The generation of programming languages or tools including, but not limited to, the following ranges:

C/c++/c# Write

Java Write generation

It generation

Python writes

Tutoring Programming Jobs

The MATLAB Generation writes

Haskell writes

Processing Write

Linux Environment Setup

Rust Generation Write

Data Structure assginment Data structure generation

MIPS Generation Writing

Machine Learning Job Writing

Oracle/sql/postgresql/pig database Generation/Generation/Coaching

Web development, Web development, Web site jobs

Asp. NET Web site development

Finance insurace Statistics Statistics, regression, iteration

Prolog write

Computer Computational Method Generation

Because of professional, so trustworthy. If necessary, please add qq:99515681 or e-mail:[email protected]

: Codinghelp

TCP, UDP network programming job generation, write C language TCP program network programming using C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.