Επικοινωνία μεταξύ διεργασιών Απομακρυσμένες κλήσεις...
-
Upload
drake-garner -
Category
Documents
-
view
29 -
download
0
description
Transcript of Επικοινωνία μεταξύ διεργασιών Απομακρυσμένες κλήσεις...
1
2011
.
2
.
3
:
(send). () ().
(receive). () .
(synchronous) (blocking) .
(asynchronous) - (non-blocking) .
.
4
:
blocking send receive ( blocking non-blocking) .
, blocking receive send ( blocking non-blocking) .
:
non-blocking send buffer. .
non-blocking receive buffer ( ) ( background).
.
5
/ :
+ ,
. .
/ :
+
. non-blocking receive . non-blocking receive.
.
6
internet [IP , ]. . .
IP S , S.
(binding service) [IP , ] . server .
Sockets (ports)
.
7
sockets . BSD Unix .
socket .
IP 195.251.122.70
IP 195.251.123.232
server
socket
socket
Sockets ports
.
8
(. ftp) (. 21). . .
.
216 = 65536
socket (transport protocol) UDP TCP.
UDP (User Datagram Protocol)
.
9
. .
.
internet (Domain Name Service - DNS) (. www.teithe.gr) IP (. 195.251.239.211)
Voice Over IP (VOIP) () internet
UDP
.
10
UDP
UDP
.
11
:
: < 216 bytes (64 Kbytes) < 8 Kbytes
Blocking: non-blocking send blocking receive
Timeout: blocking receive server .
:
: () checksum error ( bit ) () buffer
TCP
.
12
TCP socket SC socket SS . socket ( SC ) socket ( SS )
TCP
.
13
TCP. .
HTTP (HyperText Transfer Protocol) web browsers web servers.
FTP (File Transfer Protocol)
Telnet
SMTP (Simple Mail Transfer Protocol) email
TCP
.
14
: < 1500 Bytes
: TCP .
: TCP . , ( ) .
:
TCP
.
15
()
Timeout: . checksums. .
.
( o timeout)
UNIX
.
16
Sockets UDP datagrams
Client:
Server:
struct sockaddr_in ClntAddr;
struct sockaddr_in ServAddr;
int s, MSGLEN=strlen(message);
s = socket(AF_INET, SOCK_DGRAM, 0);
...
bind(s, &ClntAddr, sizeof(ClntAddr);
...
sendto(s, message, MSGLEN, 0,
&ServAddr,
sizeof(ServAddr));
struct sockaddr_in ClntAddr;
struct sockaddr_in ServAddr;
int s, len;
int BUFLEN=100;
char buf[BUFLEN];
s = socket(AF_INET, SOCK_DGRAM, 0);
...
bind(s, &ServAddr, sizeof(ServAddr));
...
len = recvfrom(s, buf, BUFLEN, 0,
&ClntAddr,
sizeof(ClntAddr));
UNIX
.
17
Sockets streaming
Client:
Server:
char buffer[MAXLEN];
int len, s;
struct sockaddr_in ServAddr;
int AddrLen=sizeof(struct sockaddr_in);
s = socket(AF_INET, SOCK_STREAM, 0);
connect(s, &ServAddr, AddrLen);
len = recv(s, buf, MAXLEN, 0);
struct sockaddr_in ClntAddr;
struct sockaddr_in ServAddr;
int s, newsocket;
char msg[] = "Hello World !\n";
int AddrLen=sizeof(struct sockaddr_in);
s = socket(AF_INET, SOCK_STREAM, 0);
bind(s, &ServAddr, sizeof(serv));
/* start listening, allowing a queue of
* up to 5 pending connection */
listen(s, 5);
newsocket = accept(s, &ClntAddr,
&AddrLen);
send(newsocket, msg, strlen(msg), 0);
(RPC)
(CORBA, Java RMI)
.
18
Remote Procedure Calls (RPC)
.
19
PC , PS , (client server) PC () PS .
(call) ()
S1(), S2(), ..., SN() , .
( S1, S2, ..., SN) , , .
(modules)
RPC(RPC exchange protocols)
.
20
[Request (R)]:
. . UDP
[Request Reply (RR)]:
. , . . RPC RPC. TCP.
[Request Reply Acknowledge (RRA)]:
RR
RPC
.
21
RRRRRAmessageTypeint (0=request, 1=reply)requestIdintobjectReferenceRemoteObjectRefmethodIdint Methodarguments// arrayrequest-reply
.
22
( )
Client Stub
RPC
Server Stub
RPC
.
23
client stub (= RPC). push (stack).
client stub (system call) . marshalling.
.
server stub (= client stub server).
server stub (unmarshalling) push
.
24
server stub. pop (stack).
server stub (system call) .
.
client stub.
client stub pop .
.
25
: (call by value). (call by reference), pointer , .
. . , int 4 bytes most significant byte
00 fa c3 b1
int a
01 3b d0 26
int b
00 fa c3 b1
int a=
01 3b d0 26
int b=
/
.
26
(). . , int 4 bytes 8 bytes. .
: (, , , ). .
00 fa c3 b1
int a
01 3b d0 26
int b
00 fa c3 b101 3b d0 26
int a =
int b=?
/
.
27
(binding). (bind) (session). session:
: (address) (port) .
. .
session binding session:
Binding
Session
RPC
.
28
Binding:
(non-persistent binding): , .
+
RPC
(persistent binding): . .
+ RPC
.
29
:
.
(Synchronous RPC) : . .
+ ,
. . .
.
30
(Asynchronous RPC) : . :
+
: RPC RPC 4 2...: RPC RPCs 4 2....
31
(Interface Definition Languages IDL)
SUN XDR IDL
http://www.faqs.org/rfcs/rfc1832.html
Microsoft Interface Definition Language (MIDL)
http://msdn.microsoft.com/en-us/library/windows/desktop/aa367091(v=VS.85).aspx
.
32
(RPC) ( ).
(objects) ( Java). RPC.
(Remote Method Invocation RMI) RPC. , marshalling .
.
33
(object reference): (pointer)
(Interface): , , , , .
(Action): . (target) (receiver). :
( constructor)
.
34
(Exceptions): . (throw) . (catch) . catch throw ( ).
(garbage collection): . Java ( C++) .
.
35
, (remote method invocation).
RPC . .
, . .
.
36
.
:
(encapsulation). , , ( )
cache , .
.
37
.
(identifier) .
, (. ).
. !
.
38
() IP
() (port number)
() ( 1/1/1970)
()
IP
32 bits
32 bits
32 bits
32 bits
.
39
RMI , , , .
. ( ) .
( server). CORBA
CORBA (Common Object Request Broker Architecture)
.
40
(Common Object Request Broker Architecture - CORBA) standard Object Management Group (OMG) .
(Interface Definition Language IDL) CORBA ( Java) (. C)
CORBA
.
41
server
ORB
ORB
IDL stub
Object Adapter
IDL skeleton
CORBA
.
42
ORB . ORB . .
(naming service) servers . binder.
(interface): .
IDL . IDL
Interface Factory {
Object create();
};
Factory
create(). Object
CORBA
.
43
servers
,
IDL (IDL stub) ORB
IDL (IDL skeleton)
, .
server . .
(Object adapter) .
Java RMI
.
44
Java Remote Object Invocation Java . CORBA client server (Java).
// (interface)
import java.rmi.*;
import java.util.Vector;
public interface Shape extends Remote {
int getVersion() throws RemoteException;
GraphicalObject getState() throws RemoteException;
}
Java RMI
.
45
H Java RMI (Serialization) , bytes
//
public class Person implements Serializable {
private String name;
private String place;
private int year;
public Person(String aName, Sting aPlace, int aYear) {
name = aName;
place = aPlace;
year = aYear;
}
...
}
Java RMI
.
46
.
:
Person p = new Person(Smith, London, 1934);
PersonVersion (8 byte)h03java.lang.String namejava.lang.String placeint year5 Smith6 London1934h1( bytes ):
Java RMI
.
47
RMIregisrty (binder) servers. registry .
registry Name
:
computerName : port / objectName