Networking by Example Noury Bouraqadi - - PowerPoint PPT Presentation

networking by example
SMART_READER_LITE
LIVE PREVIEW

Networking by Example Noury Bouraqadi - - PowerPoint PPT Presentation

Networking by Example Noury Bouraqadi http://car.mines-douai.fr/noury "Deep Into Smalltalk" Spring School 8 march 2011 - Lille, France 2 Agenda Networking Basics Sockets and protocols Client vs. Server Hands-on


slide-1
SLIDE 1

Networking by Example

Noury Bouraqadi http://car.mines-douai.fr/noury

"Deep Into Smalltalk" Spring School 8 march 2011 - Lille, France

slide-2
SLIDE 2

Agenda

  • Networking Basics

– Sockets and protocols – Client vs. Server – Hands-on with SocketStream

  • Serving

– Connection vs. communication – Hands-on Concurrency

  • Complex interactions

– Exchanging objects over a network – Remote messaging Hands-on

2

slide-3
SLIDE 3

3

Socket Nework Software Process Software Process Socket

Bi-directional communication

slide-4
SLIDE 4

4

Socket Nework Software Process Software Process Socket

Device A Device B

slide-5
SLIDE 5

5

Socket Nework Software Process Software Process Socket

Device Z

slide-6
SLIDE 6

6

2 Main Transport Protocols TCP UDP

Transmission Control Protocol User Datagram Protocol

slide-7
SLIDE 7

7

TCP UDP

  • Connected
  • Reliable
  • Streams
  • Connection free
  • Unreliable
  • Limited size

2 Main Transport Protocols

slide-8
SLIDE 8

8

TCP

HTTP Focus FTP SMTP POP SSH

slide-9
SLIDE 9

9

Server

Connection Handling Process

Client A

Communication Process

slide-10
SLIDE 10

10

Server

Connection Handling Process

Client A

Communication Process Communication Process

slide-11
SLIDE 11

11

Server

Connection Handling Process

Client A

Communication Process Communication Process

Client B

Communication Process

slide-12
SLIDE 12

12

Server

Connection Handling Process Communication Process

Client A

Communication Process Communication Process

Client B

Communication Process

slide-13
SLIDE 13

13

Server

Connection Handling Process Communication Process

Client A

Communication Process Communication Process

Client B

Communication Process

Client C

Communication Process

slide-14
SLIDE 14

14

Server

Connection Handling Process Communication Process Communication Process

Client A

Communication Process Communication Process

Client B

Communication Process

Client C

Communication Process

slide-15
SLIDE 15

15

Clien ent Socket

1.

  • 1. Co

Connect t to a se

  • a server

2.

  • 2. Sen

end a S a Str tring 3.

  • 3. Recei

eive a S a Str tring 4.

  • 4. Close

S

  • c

k e t S t r e a m S

  • c

k e t S t r e a m

slide-16
SLIDE 16

Server for Tests

16

ec echo " "Sma malltalk" " | nc nc – –lk lk 1 1234 2345

Po Port numb mber Multiple co connections Unix Unix Serve

slide-17
SLIDE 17

17

|stream| stream := SocketStream

  • penConnectionToHostNamed: 'localhost'

port: 12345. [ stream sendCommand: 'Pharo’. Transcript cr; show: (stream nextLineLf). ] ensure: [ stream close]

slide-18
SLIDE 18

18

Simp mplest Possible e Server

1.

  • 1. Listen

en o

  • n

n so some p port rt 2.

  • 2. Ac

Accept 1 si 1 singl gle clien ent co connection 3.

  • 3. Sen

end a S a Str tring 4.

  • 4. Recei

eive a S a Str tring 5.

  • 5. Close
slide-19
SLIDE 19

Client for Tests

19

ec echo " "Sma malltalk" " | nc nc lo localhost 1 1234 2345

Po Port numb mber Unix Unix Ho Host

slide-20
SLIDE 20

20

connectionSock := Socket newTCP. [ connectionSock listenOn: 12345 backlogSize: 10. interactSock := connectionSock waitForAcceptFor: 30. stream := SocketStream on: interactSock. stream sendCommand: 'Pharo Server!’. Transcript cr; show: stream nextLineLf. ] ensure: [ connectionSock closeAndDestroy. stream close.]

slide-21
SLIDE 21

21

Luc: I’m struggling with the robots

  • Noury: Which robots? WifiBots or

Robulabs?

  • Luc: I need to setup the internal board of

Robulab #2

  • Tw

Twit itter li like

slide-22
SLIDE 22

22

Multi-threa eaded Se Server 1 1 pr proce cess fo for co connections 1 1 pr proce cess fo for ea each clien ent Sy Sycnrho honiza izatio ion is is nee eeded

slide-23
SLIDE 23

23

Multi-threa eaded Se Server 1 1 pr proce cess fo for co connections 1 1 pr proce cess fo for ea each clien ent Sy Sycnrho honiza izatio ion is is nee eeded

fo fork Mu Mutex cr critical:

slide-24
SLIDE 24

24

So Socket 1 So Socket 2

10110101 10110101

Network

slide-25
SLIDE 25

Copying an object !

25

So Socket 1 So Socket 2

10110101 10110101

Network 1011 1011

10@ 10@34 34 10@ 10@34 34

110101 110101

slide-26
SLIDE 26

26

Referen enceS eStrea eam

s t r e a m e d R e p r e s e n t a t i

  • n

O f : 1 @ 3 4

slide-27
SLIDE 27

Cl Classe sses s sho should ld be be

  • n
  • n bo

both th si side des

27

slide-28
SLIDE 28

Remote messaging

28

Network

slide-29
SLIDE 29

29

pr proxy

So Socket 1 So Socket 2

10110101 10110101

dispa dispatche her

Network

slide-30
SLIDE 30

30

pr proxy id id1

So Socket 1 So Socket 2

10110101 10110101

dispa dispatche her id id1

Network

id id3

slide-31
SLIDE 31

31

Remo emote Tr Transcript

slide-32
SLIDE 32

32

Pr Prox

  • xy

Message pa passi ssing c g contr trol

  • l

(De- e-)Serializing Me Messa ssages Ga Garbage Co Collectio ion? Argumen ent pa passi ssing g by by referen ence Code Deploymen ent

slide-33
SLIDE 33

33

Pr Prox

  • xy

Message pa passi ssing c g contr trol

  • l

do doesN sNotUnde derstan and:

slide-34
SLIDE 34

34

(De- e-)Serializing Me Messa ssages Referen enceS eStrea eam strea eamedRepresen entationOf Of: : anOb Object unStrea eam: : aSt aStrin ing

slide-35
SLIDE 35

35

Di Distr tributed- Ob Objects (rST rST)

OC OCEA EAN

New ew Socket Li Libr brary

What Next?

slide-36
SLIDE 36

a Clean, Portable Networking Library

slide-37
SLIDE 37

Socket HTTPSocket SocksSocket SocketAdress ByteArray TCP+ UDP+… IPv4 +IPv6 IPv4 +IPv6

Current network library

0% tested

Dirty!

slide-38
SLIDE 38

TcpSocket UdpSocket NetworkLibraryProxyFactory WindowsLibrary LinuxLibrary Socket

networkLibrary socketID

MacOSLibrary NetworkingPlugin WrapperLibrary

OCEAN Library

OOP

1 % t e s t e d

slide-39
SLIDE 39

TcpSocket UdpSocket NetworkLibraryProxyFactory WindowsLibrary LinuxLibrary Socket

networkLibrary socketID

MacOSLibrary NetworkingPlugin WrapperLibrary

OCEAN Library

P h a r

  • 1

. 3

Latest version

OOP

1 % t e s t e d

slide-40
SLIDE 40

VM Image OS

Plugin Wrapper Network API

OCEAN for Pharo 1.3

Socket Plugin Socket Library

ALL Primitives !

slide-41
SLIDE 41

VM Image OS

Posix Library Wrapper Posix Library

OCEAN for Pharo 1.4?

FFI Plugin Socket Library

OOP Smalltalk IDE

slide-42
SLIDE 42

OCEAN + FFI + Posix

50 100 150 200 250 300 350 Receive 10MB Send 10MB ms Ocean OldSocket

slide-43
SLIDE 43

VM Image Other OS

Library A Library B Library Z API α API β API ψ

Generalization

FFI

Smaller VM

slide-44
SLIDE 44

44