Post on 20-May-2015
description
Networking by Example!
Noury Bouraqadi http://car.mines-douai.fr/noury
"Deep Into Smalltalk" Spring School 8 march 2011 - Lille, France
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
3
Socket
NeworkSoftware
Process
Software
ProcessSocket
Bi-directional communication
4
Socket
NeworkSoftware
Process
Software
ProcessSocket
Device A Device B
5
Socket
NeworkSoftware
Process
Software
ProcessSocket
Device Z
6
2 Main Transport Protocols
TCP UDP
Transmission Control Protocol
User Datagram Protocol
7
TCP UDP
• Connected • Reliable • Streams
• Connection free • Unreliable
• Limited size
2 Main Transport Protocols
8
TCP
HTTP
Focus
FTP
SMTP POP
SSH
9
Server
Connection Handling Process
Client A
Communication Process
10
Server
Connection Handling Process
Client A
Communication Process
Communication Process
11
Server
Connection Handling Process
Client A
Communication Process
Communication Process
Client B
Communication Process
12
Server
Connection Handling Process
Communication Process
Client A
Communication Process
Communication Process
Client B
Communication Process
13
Server
Connection Handling Process
Communication Process
Client A
Communication Process
Communication Process
Client B
Communication Process
Client C
Communication Process
14
Server
Connection Handling Process
Communication Process
Communication Process
Client A
Communication Process
Communication Process
Client B
Communication Process
Client C
Communication Process
15
Client Socket �
1. Connect to a server�2. Send a String �3. Receive a String �4. Close�
SocketStream !
Server for Tests 16
echo "Smalltalk" | nc –lk 12345 �
Port number�
Multiple�connections �
Unix!Serve�
17
|stream| stream := SocketStream
openConnectionToHostNamed: 'localhost' port: 12345.
[ stream sendCommand: 'Pharo’. Transcript cr; show: (stream nextLineLf).
] ensure: [ stream close]
18
Simplest Possible Server�1. Listen on some port �2. Accept 1 single client connection�3. Send a String �4. Receive a String �5. Close�
Client for Tests 19
echo "Smalltalk" | nc localhost 12345 �
Port number�
Unix!Host �
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.]
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 ----------
Twitter�like �
22
Multi-threaded Server�
1 process�for connections �
1 process�for each client �
Sycnrhonization �is needed�
23
Multi-threaded Server�
1 process�for connections �
1 process�for each client �
Sycnrhonization �is needed�
fork�
Mutex �
critical: �
24
Socket �1 �
Socket �2 �
10110101 �Network
Copying an object ! 25
Socket �1 �
Socket �2 �
10110101 �Network
1011
10@34 � 10@34 �
110101
26
ReferenceStream�
streamedRepresentationOf: 10@34
Classes should be �on both sides �
27
Remote messaging 28
Network
29
proxy�
Socket �1 �
Socket �2 �10110101 �
dispatcher�
Network
30
proxy�id1 �
Socket �1 �
Socket �2 �10110101 �
dispatcher�
id1 �
Network
id3 �
31
Remote �Transcript �
32
Proxy�
Message�passing control�(De-)Serializing �
Messages�
Garbage �Collection?�
Argument passing �
by reference�
Code�Deployment �
33
Proxy�
Message�passing control�
doesNotUnderstand: �
34
(De-)Serializing �Messages�
ReferenceStream�
streamedRepresentationOf: anObject �
unStream: aString�
35
Distributed-Objects (rST)�
OCEAN �New Socket �
Library �
What Next?
a Clean, Portable Networking Library
Socket
HTTPSocket SocksSocket
SocketAdress
ByteArray TCP+
UDP+… IPv4
+IPv6 IPv4
+IPv6
Current network library
0% tested
Dirty!
TcpSocket UdpSocket
NetworkLibraryProxyFactory
WindowsLibrary
LinuxLibrary
SocketnetworkLibrarysocketID
MacOSLibrary
NetworkingPluginWrapperLibrary
OCEAN Library
OOP 100% tested
TcpSocket UdpSocket
NetworkLibraryProxyFactory
WindowsLibrary
LinuxLibrary
SocketnetworkLibrarysocketID
MacOSLibrary
NetworkingPluginWrapperLibrary
OCEAN Library
Pharo 1.3
Latest
version
OOP 100% tested
VM
Image
OS
Plugin Wrapper
Network API
OCEAN for Pharo 1.3
Socket Plugin
Socket Library
ALL Primitives !
VM
Image
OS
Posix Library
Wrapper
Posix Library
OCEAN for Pharo 1.4?
FFI Plugin
Socket Library
OOP Smalltalk
IDE
OCEAN + FFI + Posix
0
50
100
150
200
250
300
350
Receive 10MB Send 10MB
ms Ocean
OldSocket
VM
Image
Other OS
Library A
Library B
Library Z
API α API β API ψ
Generalization
FFI Smaller VM
44