You are on page 1of 22

1. ............................................................................................................

2
2. ............................................................................ 2
3. .................................................................................................. 2
4. ........................................................................... 4
5. .................................................................................... 5
6. ................................................................................... 6
7. ...................................................... 9
8. ............................................................................ 11
9. .................................................................................................. 12
10. IP............................................................ 13
11. ........................................................... 14
12. ....................................................................... 15
13. Java......................................................................................... 18
13.1. ...................................................................................... 18
13.2. ....................................................................................... 19
14. ...................... 20

1 of 22

1.

,

. ,
. .

2.

:
(. circuit-switched)
, .
. ,
. ,
(. bandwidth) .
(. packet-switched)
.

. (
) ,
( ,
). Ethernet
. ,

.

3.

( ) ,
. ,
, ,
. ,
,
, .


, , ....

.

2 of 22


,
().
.
Ethernet .
OSI
, 1977 .
:


,
,
7
,
, .

( ).
6

.
,
, .
5

.
-
,
4
, , -
.

.
3

.


,

.
2
Media Access Control (MAC)
Logical Link Control (LLC). MAC

.
LLC ,

3 of 22

.

1 , ,
.

4.


.
(. Local Area Network LAN)
( , )
,
( 1 Mbps 1 Gbps) .
LAN ,
. LAN
. ,
, Macintosh, Sun, ....
() LAN .
LAN, .

PCI PCMCIA .
(. Network Interface Card NIC).
( )
LAN.
:

:
o STP:
o UTP: (e.g. ,
Ethernet 10/100BaseT)

:
o ( )
o (. 10Base5, ThickNet). .

(. hub) LAN .
(. switch)
.

.

4 of 22

LAN ( 2).

(WAN) .
CSU/DSU (Channel Service Unit/Data Service Unit).

( ).
LAN TDM (time-division multiplexed) (.
1 ). 1 (
1) 24 2 Mbps. 3
34 Mbps.
thernet . 1970-
Xerox PARC IEEE 802.3 .
.
.
.

.
Ethernet 100 Mbps 1 Gbps.
Ethernet 10 Mbps.
Ethernet Carrier Sense Multiple Access
with Collision Detection (CSMA/CD). ,
( ).
,

. , .
CSMA/CD .
Ethernet ,
10Base5 500 m.
10Base2
( 200 m).
,
. Ethernet
10/100BaseT,
( ).
( ).

5.

- . ,
: , .
,
.

5 of 22

.
.
, ,
. :

.
(., /etc/services Unix )
.

.
.
:
-
o ,
o
o ( )
o
(
).
.

o
o
o
.
. ,

.
.

6.


. 1969
Defenses Advanced Research Projects
Agency (ARPA). ,

. Internet Protocol IP.

.
IP .
IP 32- , IP .

6 of 22

, IP
. IP (.,
Ethernet ) .
32- 232 4
. IP
IP ,
4
. ,
.
,
,
. ,
216.109.112.135 216.109.15.34. 16
.
216.109 ( 16
)
()
.
IP :
-
.
- .

.

. 16- , 65.536
, 65.536 . .
.
, .


. IP
.

IP
. , IP
135.250.68.43 0000111 11111010
01000100 00101011. 10,

7 of 22

B. 14
(00 0111 1111 1010) 16
.

,
IP
. .


. , B 16
. 8
8 .
IP ,
.
IP :
0
.
.

.
1
.
. 195.95.34.255
195.95.34.
1
.
1
.
.
127.0.0.1.
1110
D. 28
.
.
.
() .

IP ,
.
. , eurm.edu.mk
eurm (mk),
(edu). IP
. , (/etc
/hosts) .

8 of 22

, . ,
, ,
.

.
(. Domain Name Servers DNS).

7.

1980-
1990- , IP
.
. , IP .
IP
.
IP IP (
).
C, 16.000
A B.
IP 4 ,
. ,
C 254 (
) .
1000 , B (
16.382). B 65.534 ,
64.000 , 98% .
,
(. Classless Inter-Domain Routing
CIDR).

IP .
(, B C)
IP . , IP

. ,
1000 , B,
64.000 . , 22- ,
10 , 1022 .
,
,
. CIDR IP
32- IP

9 of 22

( , 128.6.13.3/16,
16 16 ). CIDR
, .
,
.
CIDR IP
.
IP : .
,
.
.
, .
( .,
ISP
ISP),
;
(.., ,
).
IP
.

, .. IP .
() IP
, .
,
gateway .
gateway- (
IP ). , gateway-
,
. ( ) , gateway-


. network address translation (NAT).
NAT
.
(..
) gateway-.

IPv6

IPv6 (Internet Protocol version 6) IPv4,


. IPv6
,
,

10 of 22

. IPv4 232 ( 4.3 ) ,


,
, which is inadequate for giving even one address
to every living person, let alone supporting embedded and . IPv6
2128 51028 6.5
. IPv6 . 1.

Version (4 bits) Priority (4 bits) Flow label (24 bits)


Payload length (16 bits) Next header (8 bits) Hop limit (8 bits)

Source address
(128 bits)

Destination address
(128 bits)

. 1 IPv6

8.

IP .
IP
IP (. driver). IP
:

( ):
- (Maximum Transfer Unit -
MTU)
-
-


. ,
, IP
.



(. checksum).


.
:

11 of 22


-
- IP
IP
-
-

.
, Ethernet Ethernet
(. broadcast) . IP
. (..
) Ethernet
. IP
,
( ).


Address Resolution Protocol (ARP). ARP IP
(., Ethernet) :
1. ARP
2. ( ) Ethernet
IP
3. ( timeout)

9.


(.,
Ethernet ). .

. ,
.
. IP ,
. ,
. ,
.
, (
, netmask), () .
IP (

12 of 22

),
.

.
,

.

10. IP

IP .
Internet Control Message Protocol
ICMP. ICMP
. IP
, ( ,
).
IP (. 2) :
TCP Transmission Control Protocol
o ( )
o
o
o

UDP User Datagram Protocol


o ()
o
o
o
o

13 of 22

. 2 TCP UDP IP

11.

. ,
() (TCP) (UDP)
?

.
.
(
. socket), Berkeley.
:







( )

.
:

14 of 22




o , , ,



o
o

12.

.

Solaris Unix
( ).

1.

int s = socket(domain, type, protocol)

.
domain
.
AF_INET (IP ), AF_UNIX ( ), AF_NS (Xerox
Network Systems ).
type .
: SOCK_STREAM (
), SOCK_DGRAM ( ), SOCK_RAW ( IP
).
protocol
.

.

( ).
.

2.

15 of 22

.
.

.

. .

(., /etc/services).
:

int error = bind(s, addr, addrlen)

s 1, addr
(struct sockaddr *) addrlen
.
.
.
. ,
( ,
).

3. ()

,
connect:

int error = connect(s, serveraddr, serveraddrlen)

s (type int) serveraddr


(struct sockaddr *).
, connect
(serveraddrlen).
,
.

3. ()

,
.
listen:

16 of 22

int error = listen(s, backlog)

backlog
. listen,
.
accept,
.

. , ,
, accept
. accept :

int s;
struct sockaddr *clientaddr;
int clientaddrlen = sizeof(struct sockaddr);
int snew = accept(s, clientaddr, &clientaddrlen);

clientaddr
. accept
.
, ,
. .
(
).

4.


read ( ).
. send/recv
read/write (flags)
out-of-band .
sendto/recvfrom send/recv

( ). , sendmsg/recvmsg

.
? .
read/write send/recv -
, sendto/recvfrom sendmsg/recvmsg
.
(SOCK_STREAM)
(SOCK_DGRAM)
(reads) (

17 of 22

) (
(writes) ).

5.


read/write :

shutdown(s)

(
, ) ():
. ,
. , accept
. , :
(., read ).
fcntl. ,

fcntl(s, F_SETFF, FNDELAY);

s .

13. Java

Java
. java.net .
, (
) .

13.1.

,
:

Socket s = new Socket(host, port);

,
,
(

18 of 22

)
. ,
(UDP/IP) who 513 eurm.edu.mk:

Socket s = new Socket("eurm.edu.mk", 513, false);

true false
.
InputStream and OutputStream:

InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();

InputStream OutputStream java.io read


write , ,
.
, close:

s.close();

13.2.


. ,
( listen). Java,
ServerSocket. . :

ServerSocket svc = new ServerSocket(int port, int backlog);

, port ( ) ,
backlog
(
).
ServerSocket, accept ( )
:

Socket req = svc.accept();

, accept .

InputStream OutputStream . :

DataInputStream in = new DataInputStream(req.getInputStream());

19 of 22

PrintStream out = new PrintStream(req.getOutputStream());

, stream-, reader-, writer-, .,


. , . ,
:

in.close();
out.close();
s.close()

, :

in.close();
out.close();
req.close();
svc.close();

14.


{, }.
, , accept,
,
.
.
. socket
() . ,
bind
listen.
accept . ,
.
socket,
(. protocol control block PCB) 0.
PCB :

20 of 22

bind , .
0 ( )
1234:

, .
PCB 0:

.

PCB (
7801):

connect (
1234), ( IP ) .
125.250.68.43,
192.11.35.15:

server: 135.250.68.43:7801 192.11.35.15:1234.

, . , accept,
.
PCB ,
/
:

21 of 22


.
PCB :

(
connect). ,
PCB-
. , PCB
.
, (
, = 0, 0),
, (
, , , ).

22 of 22

You might also like