Professional Documents
Culture Documents
3
1. Java Sockets
) Echo service
Java 4.5 4.6
(www.cdk5.net/ipc)
echo TCP streams.
M javac command line
client (TCPClient.java) server (TCPServer.java).
server client.
:
java TCPServer
java TCPClient Hello SDY50 Tomos B localhost
server IP
port number / .
-1-
50
Bye. .
.
, Client,
TCPClient . Client
( {localhost, 5050})
.
Client
socket server
socket / Java, streams
(.. BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))
While ( socket stream != null)
Begin
Bye. to loop
socket stream
EndWhile
KKServer Protocol.
Server
.
KKServer
listening socket
While (true)
Begin
socket accept
I/O Java, streams
Protocol
output = processInput(null) // Protocol
(output)
While (input = socket stream != null)
-2-
50
Begin
output = processInput(input)
(output)
output = Bye. to loop
EndWhile
EndWhile
. H
processInput Protocol.
( 1).
(input)
(output)
.
AWAIT
[input==null]/
outpout="Knock! Knock!"
KNOCK_
KNOCK_
SENT
[input!="Who's there?"]/
outpout=<error msg> +
"Knock! Knock!"
[input!="y"]/outpout="Bye."
"]/
t=="y
ck!"
[inpu ock! Kno X
A
n
M
K
"
=%
o u t=
outp tRound +
n
curre
[inpu
t
!=na
me s
outp [currentR
o u t=
ound
<
"Kno error ms ]+" who?
ck! K
g
"]/
n o ck > +
!"
MORE
[input==names[currentRound]+" who?"]/
outpout=punch_line[currentRound] +
"Want more? (y/n)"
NAME_
SENT
[input=="Who's there?"]/
outpout=names[currentRound]
1.
:
private String[] names = { "You", "DNT", "Atch", "Who", "Who" };
private String[] punch_line = { "Did you call?",
"Your DeNTist! I wont hurt you!",
"Bless you!",
"Is there an owl in here?",
"Is there an echo in here?" };
-3-
50
-
http://joke5.co.uk/joke/Category:Knock_Knock_Jokes
:
JAVA API TCP streams
Java.
1 KKProtocol.
:
.
, (threads)
.
:
KKServer threads
While (true)
Begin
thread
EndWhile
To thread
(Server).
.
-4-
50
:
) input output;
) Election Java RMI.
) Election
.
Election (Maybe invocation, At-Least-Once
Invocation, At-Most-Once Invocation);
) Election
.
) Election
.
).
3. (threads)
) threads, ,
;
) file server caching (hit ratio)
80%. sever 5 ms CPU time,
caching , 15 ms / .
server (
/sec), :
i) server (single-threaded)
ii) o server -
iii) server
4.
web-based .
.
:
-5-
50
(entry ticket) (
)
(
)
( ,
, , ,
),
.
,
(web service provider)
.
5. Pastry
(P2P) ,
(overlay routing) Pastry,
b=4 ( GUIDs) L=8 . GUID:
65a1fc D: e232fc, :
GUIDs 4
; ( ?)
;
( Figure 10.6 Distributed
Systems)
-6-