Purpose: Understand the one-way chat program and fix the attached source code. I
ID: 3830291 • Letter: P
Question
Purpose:
Understand the one-way chat program and fix the attached source code.
Instruction:
The attached server3.c and client3.c provides a simple one-way Chat application . Compile and run the server3 and client3. The below screen shots shows the operations.
1. There is no space betwen words in client side.
HInt: In server3.c, study the scanf() function and replace it with a proper function such as gets() or fgets()
2. While the connection is set up, If one types Ctl-C in server to kill the server process. The client will keep printing a number line endlessly
HInt: In Client3.c, when read() or recv() function can not read any message from server when the server is out of service, they return 0.
In this step, you are required to modify server3.c and client3.c to fix the above problems.
Thing to submit:
A screen shot that shows the above problems are fixed.
Submit updated server3.c and client3.c files.
Clinet3.c
Server3.c
e.keana.edu Pu eve bash-4.1$ Server starting up server program Enter strings to send to the client program or /Q' to quit. Waiting for connection from remote machine. Server got connection from 131. 125.4.250 hi how are you hope everything is fine with you eve kean edu PuTTY -bash-4.1$ client eve kean edu Starting client program. GOODBYE! -bash-4.1$ Waiting for messages from the server 3 1 hi 2. howar you! 3. hopeeverythingisfinewithyou. SERVER IS CALLING IT QUITS GOODBYE -bash-4.1Explanation / Answer
Hi,
Problem 1 - server sending strings with space but client receiving them without spaces
Answer 1 - instead of scanf, which takes the string till the space, you should use gets. So, change the line in server3.c from
Problem 2 - Server sends ctrl-c and client print infinte loop.
Answer 2 - Probably, the issue here is checking the read value and comparing it with 0 instead of -1. So change the line in client3.c
This will solve the problem number 2.
Thanks
Nikhil jain
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.