






 
Networking
Brutálně vyhrnuto z BookMorphu. Snad si s tím nějak poradíte. 
Squeak Networking
Designing Networked Applications
Architecture
 - Dumb Terminals (TN3270)
 - Client-Server (WWW)
 - Thin Client
 - Fat Client
 - Distributed Computation (Plan 9)
 - Peer to Peer (Many LAN games)
 - N-tiered (Business Apps) 					http://www.macromedia.com/devnet/mx/coldfusion/articles/ntier.html
 - Distributed Objects (COM/CORBA)
Design for Performance
 
 - Connection Pool
 - Cache
 - Client Design
 - Replication
Give UI feedback for long requests.
Protocols ? How do we talk?
 Typically we design on top of standard protocols: UDP, TCP, HTTP, etc.
 Generally use sockets or other built-in mechanisms
 May need lower-level access (serial ports etc.)
 May use higher level protocols: RPC, COM, RMI, SOAP
Protocol Design
No matter what, we usually worry about 3 things:
	  - Connection
	  - Service
	  - Disconnection
Connection typically handled by lower-level protocol (establishing socket or web connection)
Disconnection tricky sometimes.  Normal disconnect vs. system problem. (Heartbeats)
Protocols
Service protocol requests = what we usually need to design the most.  
Protocols vary widely based upon fundamental requirements.
Need to let other machine know:
 	- What kind of a message is this? (may use integer codes)
  	- What is body of message? (often character strings)
Typically we show design as Message Sequeance Charts.
State vs. Stateless Servers
 - State:  The server maintains information about what the client is trying
   to do.  Subsequent queries can leverage off previous information.
 - Stateless: The server processes each request independently.  No
   information remains between queries.  Good for error recovery.
Squeak Networking - Socket
 - Socket Class - base for other specializations (FTP, HTTP, POP, SMTP)
 - Socket initializeNetwork (set up networking on the machine)
 - Socket tcpCreateIfFail: [block] (create an unconnected TCP socket)
 - Socket udpCreateIfFail: [block] (create an unconnected UDP socket)
For clients:
 - connectTo: hostaddr port: portnumber 
 -	connectNonBlockingTo: hostAddress port: port
		- followed by waitForConnectionUntil: timeout
Socket
For server:
 - listenOn: portnumber (nonblocking!)
 - waitForAcceptUntil: deadline (in ms)
   Then just loop as long as socket is valid to get data.
   [socket isConnected] whileTrue: [
		socket dataAvailable ifTrue:
			[n := socket	receiveDataInto: buffer.
			socket sendData: buffer count: n]].
   In this case we are echoing the data back.
Socket
close (client)
waitForDisconnectionFor: deadline (client)
closeAndDestroy (server)
NetNameResolver
TCP/IP style network name lookup and translation facilities.
	- NetNameResolver addressForName: 'st.cs.uiuc.edu'
	- NetNameResolver nameForAddress: hostAddress timeout: secs
Socket examples
Client-server examples (TCP, UDP)
	-  See OldSocket examples!!!
(V souèasné verzi Squeaku koexistuje Socket a OldSocket. OldSocket vy¾aduje inicializaci, jinak je funkèní zhruba jako Socket, který je lépe implementován)
Socket examples
SocketStream example
finger: userName
	"SocketStream finger: 'stp'"
	| addr s |
	addr _ NetNameResolver promptUserForHostAddress.
	s _ SocketStream openConnectionToHost: addr port: 79.  "finger port number"
	Transcript show: '———- Connecting ———-'; cr.
	s sendCommand: userName.
	Transcript show: s getLine.
	s close.
	Transcript show: '———- Connection Closed ———-'; cr; endEntry.
Clients for common protocols
ProtocolClient  subclases 
	FTPClient
	SMTPClient
	POP3Client
HTTPClient
FTPClient
ftp := FTPClient openOnHostNamed: 'st.cs.uiuc.edu'.
ftp loginUser: 'anonymous' password: 'janousek@fit.vutbr.cz'.
ftp changeDirectoryTo: 'pub/Smalltalk/Squeak'.
ftp pwd inspect.
ftp getFileList inspect.
ftp ascii. "nebo binary"
ftp getFileNamed: 'README' inspect. 
"ftp deleteFileNamed: 'aaaaa'.
ftp renameFileNamed: 'aaa' to: 'bbb'.
ftp makeDirectory: 'ddddd'.
ftp deleteDirectory: 'ddddd'.
ftp putFileNamed: 'ffff' as: 'gggg'.
ftp putFileStreamContents: aStream as: 'aaaa'   "
ftp closeDataSocket.
HTTP client
HTTPSocket does most of work:
	s := HTTPSocket  httpGet:  'http://www.fit.vutbr.cz' .
	This returns a stream.  A contents will give html page text.
See HTTPSocket class.
See also HTTPClient class.
HTTP client usage examples
HTTPSocket class>>httpFileInNewChangeSet: url
	"	HTTPSocket httpFileInNewChangeSet:
 		'206.18.68.12/squeak/updates/83tk_test.cs'	 "
	| doc |
	doc _ self httpGet: url accept: 'application/octet-stream'.
	doc class == String ifTrue: [self inform: 'Cannot seem to contact the web site'].
	doc reset.
	ChangeSorter newChangesFromStream: doc named: (url findTokens: '/') last.
HTTP client usage examples
HTTPSocket httpShowGif: 'http://www.google.com/images/logo.gif'
Squeak Web Services
-  (Historie: PWS - Personal Web Server)
-  Comanche (from SqueakMap)
-  HttpView (from SqueakMap)
-  SeaSide (from SqueakMap)
Comanche 
HttpService - a comanche service that listens for inbound HTTP connectinos on a given port.
Usage of Comanche (1)
-  Create a subclass overriding the #processHttpRequest: method 
(an HttpRequest is passed as the sole argument to this method).
  The #processHttpRequest: method should always answer an instance of 
  an HttpResponse. 
-  Starting and stopping instances of this class will start and stop listening on 
the given port number.
 	Socket initializeNetwork.
	aHttpService := MyHttpService on: 8080 named: ''Example Http Service''
	aHttpService start
	aHttpService stop "neblokujici, asynchronní"
	aHttpService waitForStop
	aHttpService waitForStopUntil: deadline
	aHttpService kill
Usage of Comanche (2)
You may also use instances of this class in a pluggable manner rather than subclassing (see examples below).
	(HttpService on: 8080 named: ''Example Http Service'')
		onRequestDispatch: #processRequest: to: SomeGlobal;
		start
	(HttpService on: 8080 named: ''Example Http Service'')
		onRequestDo: 
			[ :httpRequest | SomeGlobal processRequest: 	httpRequest ];
		start
Comanche modules
ModuleAssembly + ComancheModule subclasses - framework for building a hierarchy of modules (#addAssembly:, #addModule:, #addPlug:). Moduly provádìjí pre/postprocessing dotazu/odpovìdi nebo provádìjí kompletní zpracování dotazu. Pøíklady: logování, autentizace, souborový server (poskytuje klasické html stránky v souborech).
	| ma |
	ma _ ModuleAssembly core.
	ma addPlug: [ :request | HttpResponse fromString: 'Hello World!!!'].
	(HttpService startOn: 8080 named: 'Example') module: ma rootModule.
Comanche modules
	| ma |
	ma := ModuleAssembly core.
	ma documentRoot: FileDirectory default fullName.
	ma directoryIndex: 'index.html index.htm'.
	ma serveFiles.
	(HttpService startOn: 8080 named: 'Example') plug: ma rootModule
HTTPView
-  Framework pro Web UI, modul pro Comanche (HttpService).
-  Views (podtøídy HVHttpView) tvoøí hierarchii s vrcholem HVRootView (rootView).
-  Dotaz se øe¹í instanciací View a voláním metody stejného jména, kdy¾ neexistuje, volá se #default.
-  Metoda zpracuje aHttpRequest a vrátí objekt, který rozumí zprávì 	#asHttpResponseTo:  (aString nebo aHVHtmlBuilder). 
Výsledná odpovìï je pak vrácena serveru Comanche.
-  View má model (doménový objekt), který se vytváøí pøi registraci slu¾by
a pøe¾ívá v¹echny dotazy (pozor na soubì¾ný pøístup).
-  Prostøedky pro zpracování sezení a u¾ivatelské úèty
-  Start:	#startOn: port mode: #deployment
- automaticky se zaregistuje se do hierarchie (rootView) a nastartuje se
	- debugging modes: #deployment | #debug | #verbose  
HTTPView examples
HVHelloWorld start		"nebo startOn: port"	
	ExternalUnixOSProcess command: 'mozilla http://localhost:8080'
	ExternalUnixOSProcess command: 'mozilla http://localhost:8080/hello'
	HVHelloWorld stop
HVSimpleForms start 	
	ExternalUnixOSProcess command: 'mozilla http://localhost:8080/megaform1'
	ExternalUnixOSProcess command: 'mozilla http://localhost:8080/megaform2'
	ExternalUnixOSProcess command: 'mozilla http://localhost:8080/simplefield'
	HVSimpleForms stopAll
HVFileDirectoryView start
	HVFileDirectoryView stopAll
HVTodoListView start
	HVTodoListView stop
	Pozn: Model se vytváøí tøídní metodu #createModel, která se volá automaticky pøi startu 
		(zaøídí to metoda #startOn: zdìdìná od HVHttpView).
Seaside
-  Výkonný framework pro tvorbu webových aplikací
-  Vysokoúrovòovìj¹í ne¾ servlety a HTTPView
-  Implenetace pomocí kontinuací
-  Vhodný pro velmi rozsáhlé aplikace
-  Podpora pro debugging
-  Pou¾ívá se v nejúspe¹nìj¹ích komerèních aplikacích Squeaku 
-  Existují i verze pro jiné dialekty Smalltalku
-  Je na SqueakMap
-  Více informací na 
		http://beta4.com/seaside2/
Seaside examples
WAKom startOn: 9090
WAKom stop
WADispatcher default entryPoints
WADispatcher default registerEntryPoint: ..... at: .....
WADispatcher default removeEntryPoint: ..... 
http://localhost:9090/seaside/counter
http://localhost:9090/seaside/multi
http://localhost:9090/seaside/screenshot    (user/passwd = seaside/admin)
http://localhost:9090/seaside/config
http://beta4.com/seaside2/
http://www.iam.unibe.ch/~ducasse/Web/Presentations/Seaside-0204.pdf
Swiki
-  Wiki-wiki web (pùvodnì v Perlu) = editovatelný web
-  Swiki = Squeak Wiki
-  Existují i jiné implementace, ale Swiki je Swiki ;-)
Remote Smalltalk 
rST - vzdálená komunikace objektù (obdoba Javovského RMI)
Server side:
	
	RSTBroker startOnPort: 9998 logging: false.
	exportedOrderedCollection := OrderedCollection new.
	RSTBroker instance export: exportedOrderedCollection named: 'myOrderedCollection'. 
	
Client side:
	
	remoteOrderedCollection :=  
			('myOrderedCollection@192.168.1.2:9998') asRemoteObjectID asLocalObject.
	remoteOrderedCollection add: 'Hello, Remote Squeak World!'.
OperaORB
-  a tiny ORB wrapper on SOAP, RMT
Server side:
	OperaORB init: {{#port:. 9999}}.
	OperaNamingService local at: #myOrderedCollection put: OrderedCollection new.
Client side:
	namingService := OperaNamingService host: '192.168.1.2' port: 9999.
	remoteOrderedCollection := namingService at: #myOrderedCollection.
	remoteOrderedCollection add: 'Hello, Remote Squeak World!'.
http://www.mars.dti.ne.jp/~umejava/smalltalk/soapOpera/
Nebraska
Colaborative multiuser environment - modified port of Kansas from Self
Start server in one image and client in another image on another machine ...
Croquet
Distribuované multiu¾ivatelské prostøedí s 3-D GUI
Ve vývoji
Croquet
a SketchMorph(1824)
a SketchMorph(3676)
Konec
Dotazy ?
Link to this Page
- loňská verze last edited on 15 February 2005 at 3:47 pm by libuse.fit.vutbr.cz