View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007


Networking in Squeak

1. Introduction
Networking was not required for our project. However, since one of our members did not go home during Thanksgiving (in fact, he was such a lazy aXX to delay until last minute to book his ticket, which was way more expensive than he could afford), he decided to mess with networking. Thanks to him, we experienced one of the funniest things in Squeak (we will talk about this later).

2. UML

3. Class Structure
There are four classes in our networking:

4. Data Flow
SimServer starts by specifying a port to listen for connection. It then creates a thread (process in Squeak) to wait for connections from clients. Whenever SimServer accepts a connection, it creates a socket to communicate with the client and creates a SimSocketManager to manage the socket. The SimSocketManagerís network interface will be the SimServer.
SimClient starts by specifying a port and a server address to connect to. When it successfully connects and creates a socket to SimServer, it makes a SocketManager to manage the connection. The SimSocketManagerís network interface will be the SimClient.
SimSocketManager has a thread that continuously check on the socket that it is managing to see if there is new data coming in. It yes, it will call method processFrom(data, socket) in its network interface to process the data.
Whenever a SimNetworkInterface want to send some data, it calls method send(data) in a SimSocketManager. SimClient only has only one SimSocketManager, so it is pretty to manage. However, SimServer has several SimSocketManager, so it is no easy to find out the right socket to send data to. Notice that the server normally does not send any packets unless there is a request from client. Also notice, in the processFrom, we pass in data and also the socket from which the data come. So after finishing processing incoming data, the server can use that socket to send back responses. In our project, whenever the server get something, it simply broadcast that piece of information to all clients including the sender so it is not necessary for the server to know the source of data.
1.4 Serialization
Based on our understanding, all classes in Squeak are serializable. This means that we can easily read/write an object from/to a stream. In fact, ReferenceStream supports reading/writing object from/to disk. However, this is not easy anymore when it comes to network. We tried ObjectSocket and StringSocket which, as some people stated, were able to send/receive objects through network. Unfortunately, we could not get them to run. Alternately, we used MA Serialization, a module of MA Server Ė Client, which can be found at MA Serialization works fine but the fact that we had to list all the objects that we wanted to send across network was a little annoying.
1.5 Some Entertaining Stuff
We were so influenced by Squeak that we learnt one of their hobbies: not comment code, especially the network part, so please bear with us (yah, we were partially Squeakers). If you have any question about networking in Squeak, please send email to Guarantee that he will try his best to answer your questions based on his knowledge (even though it is very limited :).
If you want to work with networking in Squeak, our first advice is BE NICE WITH SQUEAK MOUSE. That little privacy invader not just watches your stuff everywhere you go in Squeak world but also plays a vital role in deciding whether your network functions properly or not. We spent only 2 man-days to learn and write the network structure but it did not run as expected. We experienced a lot a missing information (for example send an array of 5 elements, only get 4 or even a blank buffer), or even if all information is received, the whole program just does not response or freezes. At the very last day of our project when everybody was about to give up, one of us accidentally killed the Squeak mouse and our network ran perfectly. But wait, that is not the end of the story, right after we celebrated our victory the over mouse by filing out every thing and start with a new image, the network stopped running even though we cursed and killed Squeak mouse a thousand times. Another accident happened, we started the server, connected clients and then for some unknown reasons, we pulled Squeak mouse out of the trash on the client side (maybe one of us missed that fat face so much). Guess what, the network worked again and this time, it was pretty stable. With all of that happened, we decided to abandon networking. We, however, did some demo in class and that was the funniest show everybody ever watched.
If you work with threads or sockets in Squeak, make sure that you close them properly, because if you do not do that, they will stay and haunt you forever. We happened to experience this in a painful way. Once, we started a client on port 12345, sent a packet and got back a dirty response :-D. We spent an hour to figure out where the response came from because our current server did not send back such a thing. At the end, it turned out that the response was from our old server. It was executed the day before but never got turned down and one of us saved the image, which gave the old server chance to stay alive forever.
Have fun coding in Squeak, the big thing you will learn is the world outside is beautiful.
Uploaded Image: OTIB SimNetwork UML.jpg

Link to this Page