|
By John Zukowski, MageLang Institute [Help | API Docs | Short Course | Magercises] For this Magercise you use the BeanBox, or another IDE, to design and test a nongraphical socket Bean. The Bean makes a socket connection to a server and then performs send and/or receive operations. You should design your Bean so that other users (programmers) can plug your socket Bean into their applications via an IDE. Magercise 9 Prerequisites Skeleton Code
Tasks
Where help exists, the task numbers above are linked to the step-by-step help page. Solution Source
Demonstration The test program TestConnect connects to a named host and port and interacts accordingly with the server at that port: [prompt] java TestConnect www.magelang.com 7 read back: hello [prompt] java TestConnect www.magelang.com 13 time: Tuesday, December 15, 1998 9:45:56 After loading the ClientSocket Bean, it should appear in the palette, from where it can be selected and instantiated on the worksheet:
In this case, the worksheet contains a nongraphical ClientSocket Bean and command buttons for connecting, sending, and, optionally, receiving data to and from a socket. Also, the worksheet contains instances of two different specializations of TextArea, both of which implement the SocketListener interface, one tailored to the received() and one to the sent() event notification methods. The property sheet displays the published properties:
Note that the port is set to 7, the standard echo server location. Both the "Send" and "Read" buttons have been pressed to generate the output shown in the worksheet. It's possible, of course, for the connection alone to generate output; it simply depends on the server functionality. For example, consider setting the port to 13, the standard date-time server location:
In this case, pressing the "Read" button is sufficient:
Your design and implementation will certainly differ, but the basic objective is to support connections to a server at a well-known location, as well as basic send and receive operations.
Copyright © 1998-1999 MageLang Institute. All Rights Reserved. | ||||
|
| ||||||||||||