Download presentation
Presentation is loading. Please wait.
Published byLindsey Hawkins Modified over 8 years ago
1
CS470 Programming Assignment 1 Zilong Ye
2
A Chat Application Goal: learn socket programming and implement a chat application for exchanging messages between remote users; Peer 1 Peer 3 Peer 2 Socket enables this “Hello” “Hi back”
3
Start the program Name your program as “chat” Specify the port number that the process is running on The process works like a unix shell E.g.: C://course/cs470/./chat 4545 >>
4
help Show the command manual E.g.: C://course/cs470/./chat 4545 >> help >> myip display IP address connect connect to another peer send send messages to peers …………. exit exit the program >>
5
myip Show the IP of your laptop E.g.: >> myip >> The IP address is 192.168.21.21 >>
6
myport Show the port number that the process runs on E.g.: >> myport >> The program runs on port number 4545 >>
7
connect E.g.: >> connect 192.168.21.22 5454 >> The connection to peer 192.168.21.22 is successfully established; >> Peer 2 displays the connection news and update its list On peer 2, e.g.: >> The connection to peer 192.168.21.22 is successfully established; >>
8
list List all the connected peers E.g.: >> connect 192.168.0.2 5000 >> The connection to peer 2 is successfully established; >> list id: IP address Port No. 1: 192.168.21.21 4545 2: 192.168.21.22 5454 3: 192.168.21.23 5000 4: 192.168.21.24 5000 >> On peer 2, e.g.: >> list id: IP address Port No. 1: 192.168.21.21 4545 >>
9
send E.g.: >> list id: IP address Port No. 1: 192.168.21.20 4545 2: 192.168.21.21 5454 3: 192.168.21.23 5000 4: 192.168.21.24 5000 >> send 2 Hello
10
send Peer 2 receives the message and should display the message >> Message received from 192.168.21.21: “Hello” >> list id: IP address Port No. 1: 192.168.21.20 4545 >> send 1 Hi, back >> Peer 1 receives the reply and should display the message >> Message received from 192.168.21.22: “Hi, back” >>
11
terminate Terminate the connection E.g.: >> list id: IP address Port No. 1: 192.168.21.21 4545 2: 192.168.21.22 5454 3: 192.168.21.23 5000 4: 192.168.21.24 5000 >> terminate 2 >> list id: IP address Port No. 1: 192.168.21.21 4545 3: 192.168.21.23 5000 4: 192.168.21.24 5000
12
terminate Peer 2 displays the termination news and update its connection list >> list id: IP address Port No. 1: 192.168.21.21 4545 >> Peer 192.168.21.21 terminates the connection >> list id: IP address Port No. >>
13
exit Terminate all the connections and exit the program; The other peers should display the exit news and update their peer list; E.g.: C://course/cs470/./chat 4545 >> help ……. >> list ……. >> exit C://course/cs470/
14
Useful links Socket Programming: Beej Socket Guide: http://beej.us/guide/bgnet http://beej.us/guide/bgnet Select function: http://www.mkssoftware.com/docs/man3/sel ect.3.asp http://www.mkssoftware.com/docs/man3/sel ect.3.asp
15
How to recognize the command input
16
Code structure
17
Fill out addr_info structure
18
Regular steps for socket programming
19
How to use connect
20
myip 127.0.0.1 is your “Lo” IP address, and it is NOT what we want; Create a UDP socket to contact any public DNS server (e.g., 8.8.8.8 or 8.8.4.4 by Google) to get a response from the DNS server and obtain your real IP address
21
Select based I/O
22
Select() related functions
23
Select() example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.