Stephen Woolerton wrote:
> Hi Paolo, > > I'm having a go at porting LDAPLayer from Squeak to GST. LDAPLayer uses > "SocketStream" which (I expect you know already) is a library to make it > easy to program to network sockets using a stream interface. > > GST doesn't have SocketStream and I'm wondering if there is already > something equivalent before I look at copying the SocketStream library > across to GST. Hi Stephen, I guess you do not mind if I send the message to the mailing list. There are equivalents in the Sockets package (TCP up to 3.0.x). The simplest example is as follows, from packages/sockets/Tests.st sendTest: host [ "Send data to the 'discard' socket of the given host. Tests the speed of one-way data transfers across the network to the given host. Note that many hosts do not run a discard server." "Sockets.Socket sendTest: 'localhost'" <category: 'tests'> | sock bytesToSend sendBuf bytesSent t | Transcript cr; show: 'starting send test'; cr. sock := Sockets.Socket remote: host port: 9. Transcript show: 'connection established'; cr. bytesToSend := 5000000. sendBuf := String new: 4000 withAll: $x. bytesSent := 0. t := Time millisecondsToRun: [[bytesSent < bytesToSend] whileTrue: [sock nextPutAll: sendBuf; flush. bytesSent := bytesSent + sendBuf size]]. Transcript show: 'closing connection'; cr. sock close. Transcript show: 'send test done; time = ' , (t / 1000.0) printString, ' seconds'; cr; show: (bytesToSend asFloat / t) printString; showCr: ' kBytes/sec' ] You can start a discard server using "sudo nc -l -p discard > /dev/null" if you want to try it. There are three classes: - UnbufferedSocket does no buffering at all; - StreamSocket does read buffering only; - Socket does read and write buffering only; use #flush to send data down the network. Usually you want to use StreamSocket if requests are created in a byte array and then sent to the network (common when porting from Squeak), otherwise use Socket. I'd use Socket only for interactive stuff, because buffering *is* expensive: I get 56 MB/sec. throughput with StreamSocket and 4 MB/sec. throughput with Socket. The reason is that Sockets were especially optimized in 3.1 to limit the number of copy operations, and the #nextPutAll: in the above code becomes directly a "send" with StreamSocket, with no intermediate copies. GST's API is more Smalltalk-ish (based on Streams), while Squeak's is more similar to BSD sockets. The equivalent of Squeak's receive method is #nextAvailable:into:startingAt: (there is also #next:into:startingAt: which loops if the requested number of bytes is not available, and #nextAvailable:/#next: which return a new Collection; however the latter two may stress the GC much more). HTH, Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
>
> There are equivalents in the Sockets package (in TCP package up to 3.0.x). I was looking for HTML documentation but it appears the docs are all still at version 3.0.x ... http://www.gnu.org/software/smalltalk/manual-libs/gst-libs.html (maybe there should be a comment in the web page above, to look at the source in packages/sockets/Sockets.st if running 3.1). Also, I remembered there was a Wiki article on GST streams but it is missing from the link: http://smalltalk.gnu.org/wiki/GNU_Smalltalk_extensions_to_streams Was this article relevant? > > HTH, > > Paolo Yes extremely helpful - I had been looking at the TCP package sockets deciding which socket type to use (and I'm running 3.1). Thanks Stephen _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Paolo Bonzini-2
> I was looking for HTML documentation but it appears the docs are all > still at version 3.0.x ... > http://www.gnu.org/software/smalltalk/manual-libs/gst-libs.html Should be updated indeed. > Also, I remembered there was a Wiki article on GST streams but it is > missing from the link: > http://smalltalk.gnu.org/wiki/GNU_Smalltalk_extensions_to_streams > Was this article relevant? http://smalltalk.gnu.org/wiki/missing-manual-pages shows that it is a "needed" page. I.e. not written yet. :-( Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |