-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Hi, I'd like to test GNU Smalltalk's performance as a Network server. My intention is like this: create simple echo like server and test it with my previous C based version. Then compare the numbers - I have test client in C :-). Thanks in advance. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFQGORQqspS1+XJHgRAmiwAKCnLlElwe9JiTkgCZOn3UeqfBP5TgCgkMO+ 4W187H89/2O3pu9a5uxZdCc= =HDJ8 -----END PGP SIGNATURE----- _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Thu, Oct 26, 2006 at 04:28:18PM +0900, Sungjin Chun wrote:
> Hi, > > I'd like to test GNU Smalltalk's performance as a Network server. My > intention is like this: create simple echo like server and test it with > my previous C based version. Then compare the numbers - I have test > client in C :-). > > Thanks in advance. > I can give you the pieces of code i made up when playing with the TCP package some days ago. The attachment of this mail contains SocketTest.st which should be used and loaded like this: st> PackageLoader fileInPackage: 'TCP'! Loading package TCP PackageLoader st> FileStream fileIn: 'SocketTest.st'! FileStream st> Smalltalk at: #x put: (SocketTest new)! SocketTest new "<0x2afbf7bb1ee0>" st> x start! Starting server... Got connection! ... Connect to local port 12345: $ nc localhost 12345 test [ test ] The code isn't very elegant, it's what i hacked up with my 5 days smalltalk experience. Which creates a process around the main loop of the server. This is the code of SocketTest>>#start : start 'Starting server...' displayNl. socket := TCP.ServerSocket port: 12345. socket isNil ifTrue: [ self error: 'couldn''t create ServerSocket!' ]. [ socket waitForConnection. 'Got connection!' displayNl. self handle: (socket accept) ] repeat ! The error reporting is likely not correct. 'socket waitForConnection' blocks the current process and waits until someone connected. Then (socket accept) will return a new socket with the client connection. Now to SocketTest>>#handle : handle: sock [ [ [ sock atEnd ] whileFalse: [ buffer := buffer, (sock nextHunk). sock nextPutAll: '['. sock nl. sock nextPutAll: buffer. sock nl. sock nextPutAll: ']'. sock nl. sock flush ]. ] ensure: [ sock close ] ] fork ! This forks off a new process to handle the connection socket and reads from it until EOF is seen (i don't know if 'atEnd' is the correct way to do this here!). Also error reporting is missing, i still wonder how to do it right :) Note: (sock nextHunk) is blocking the process until data arrived. I'm not sure whether the application of fork and the sockets is correct this way. Most of the ideas i got from browsing the code with the blox browser and looking at the existing networking code in tcp/Sockets.st. cu, Robin _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Chun, Sungjin
Hi,
Sorry, i forgot to attach the attachment... cu, Robin _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk SocketTest.st (1K) Download Attachment |
In reply to this post by Chun, Sungjin
On Thu, Oct 26, 2006 at 04:28:18PM +0900, Sungjin Chun wrote:
> Hi, > > I'd like to test GNU Smalltalk's performance as a Network server. My > intention is like this: create simple echo like server and test it with > my previous C based version. Then compare the numbers - I have test > client in C :-). > > Thanks in advance. Sorry, i got the topic somehow wrong in the other posts. Sorry for being so noisy. I most should've posted the stuff more as a question of mine than an answer :) cu, Robin _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
> Sorry, i got the topic somehow wrong in the other posts. Sorry for > being so noisy. I most should've posted the stuff more as a question > of mine than an answer :) > No problem. I guess Sungjin can do the same as you did -- browse the code for NetServer -- and rewrite the code with the NetServer architecture (which is a set of abstract classes that take care themselves of the forking), while still starting from somewhere. You have to subclass NetServer and NetSession. NetServer listens on a socket and creates NetSessions; NetSession parses requests and passes them back to NetServer. (Note that the request is an arbitrary object, so you can pass in your case for example an association like socket->data and do "request key nextPutAll: request value") Then, you implement your server by overriding this methods: - in the EchoServer, #newSession (answering "EchoSession new" in your case) and #respondTo: (which takes the request association and answers as I outlined above) - in the EchoSession, #next (which might be as easy as "self socket->self socket nextHunk") Note that examples and documentation are what is badly needed. Sending them will never hurt. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Robin Redeker-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Thank you very much. I needed an example for network programming too. Robin Redeker wrote: > Sorry, i got the topic somehow wrong in the other posts. Sorry for > being so noisy. I most should've posted the stuff more as a question > of mine than an answer :) > > cu, > Robin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFQI5lQqspS1+XJHgRAnADAJ9p+stvmRq+eE1XTOqNuTQ+DpoNJgCeNvjO n5kfGgAAkiKrZ/4myCfUs44= =xPOQ -----END PGP SIGNATURE----- _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Robin Redeker-2
> I'm not sure whether the application of fork and the sockets > is correct this way. Most of the ideas i got from browsing the code > with the blox browser and looking at the existing networking code > in tcp/Sockets.st. Yes, it's okay. The socket code is blocking only the current Smalltalk process -- fork is pretty cheap in gst. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
On Thu, Oct 26, 2006 at 07:42:09PM +0900, Paolo Bonzini wrote:
> > >I'm not sure whether the application of fork and the sockets > >is correct this way. Most of the ideas i got from browsing the code > >with the blox browser and looking at the existing networking code > >in tcp/Sockets.st. > Yes, it's okay. The socket code is blocking only the current Smalltalk > process -- fork is pretty cheap in gst. Thanks for answering this unasked question of mine. I already wondered how much this fork costs :-) cu, Robin _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |