Download presentation
Presentation is loading. Please wait.
Published byJunior Morgan Modified over 8 years ago
1
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW IRC, parsing, protocols COMP 112 2014 # 25
2
COMP112 25: 2 Menu Networking and Concurrency Admin Test results Wed Tutorial & Thursday Lecture: review of test and graphics assign. No Tutorial Wed 14 (Graduation Ceremony)
3
COMP112 25: 3 IRC login Login sequence: NICK pondy USER pondy 0 unused :Peter Andreae …lots of messages… including grumbling about looking up hostname :irc.ecs.vuw.ac.nz.net 001 pondy ……. :irc.ecs.vuw.ac.nz.net 002 pondy ……. :irc.ecs.vuw.ac.nz.net 003 pondy ……. :irc.ecs.vuw.ac.nz.net 004 pondy irc.ecs.vuw.ac.nz hybrid-7.2.3 …. or :irc.ecs.vuw.ac.nz.net 433 * pondy :Nickname is already in use
4
COMP112 25: 4 Protocols Rules of interaction format/structure of messages rules about what messages have to be sent when. Some network applications have complex protocols; IRC has a fairly simple protocol, especially client-server. messages are simple very little constraint on the interaction. login PING.. PONG response rules on joining channels, controlling channels, etc
5
COMP112 25: 5 Message structure format: source command arg arg arg … final-extended-argument \r\n space separated source is optional: client messages usually have no source server messages usually (always?) have the source command is either uppercase word JOIN, PING, PRIVMSG,… three digit number 004, 433…. arguments are optional final extended argument is optional and it can contain spaces. Channel names (in arg’s) start with #, or &
6
COMP112 25: 6 Message structure How do you tell the difference between source command arg arg and command arg arg arg command extended-arg the source must start with a : the command does not start with a : :irc.ecs.vuw.ac.nz PING zxsdfw \r\n PING sdfafff ewrrrf\r\n The extended argument must start with a : everything from the : to the end of line is the argument PRIVMSG ChatBot :This is a message for you \r\n
7
COMP112 25: 7 Parsing the message String line = input.nextLine(); Scanner lineScanner = new Scanner(line); String source = “”; String command = lineScanner.next(); if (command.startsWith(“:”) ){ source = command.substring(1); command = lineScanner.next(); } read the arguments, one at a time. checking if start with : Do you check for the : before or after reading the token? after: now have to put the arguments “back” into the rest of line. before: how?
8
COMP112 25: 8 Scanner hasNext(String pattern) hasNext() true iff there is any token in the input hasNextInt() true iff there is a token and it is an integer hasNext(“A.B*”) true iff there is a token and it matches the pattern “A.B*” Pattern language:. means “any character” * means “any number of repetitions of the previous (including zero)” AxBBBBBB, A!B AA lots more options for specifiying more complex patterns. Can use this to “peek” at the next token to see if it matches a required pattern before you read it.
9
COMP112 25: 9 Protocol rules NICK message required from client If the is a PASS message (password), it must precede the NICK message. When the server sends a PING message, the client must respond quickly with a PONG, else client will be disconnected When server sends a list of channel names, there is one message for each name, with a final message to indicate the end of list (commands 322 and 323). ….
10
COMP112 25: 10 Other Networking Issues Encryption How can you ensure that only the intended recipient can read the message. Authentication. How can you be sure that the message you got came from the sender it claims to be from. email protocol is not authenticated! irc server might require authentication (irc.ecs.vuw.ac.nz doesn’t) How can you authenticate a message?
11
COMP112 25: 11 AI: Games Where is AI used in Games?
12
COMP112 25: 12 Min-Max search 2-person, turn-taking games (eg, board games)
13
It’s O’s turn. What should they do? What should O do? 13
14
O’s choice X’s Choice It’s O’s turn: what should O do? Work backwards to determine status of earlier positions X will try to make O lose
15
O’s choices O’s choice X’s Choice It’s O’s turn: what should O do? Work backwards to determine status of earlier positions O will try to win
16
O’s choice X’s Choices It’s O’s turn: what should O do? Work backwards to determine status of earlier positions X will try to make O lose
17
O’s choice It’s O’s turn: what should O do? Work backwards to determine status of earlier positions O will try to win
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.