. .

st4u

ST 4U 252: Basic Socket Communications in VA

June 29, 2012 11:54:55.145

Today's Smalltalk 4 You looks at simple socket communications, using VA Smalltalk and VisualWorks Smalltalk to set up an example. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

TCP.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at using sockets for basic communication in VA Smalltalk. In order to get something real, we'll set up a socket server in VisualWorks, and have VA Smalltalk interact with that. To get started, load the TCP support into VA:

TCP

That loads in the basic support we need. We'll be running two bits of code - the first bit below is in VW, the second, in VA:


"In VisualWorks"
SocketAccessor exampleIPServer.


"get port number from VW Transcript, then run this"
socket := AbtSocketStream openAsClientToHost: 'localhost' port: 49174.
socket nextPutAll: 'hello'.
socket cr.
socket flush.
ans := socket upToEnd.
Transcript show: 'From VW: ', ans; cr.
socket close.


Over in VisualWorks, that sets up a simple server that waits for a string terminated by a CR. We dutifully send that from VA, and then get back a similar string from VW. On both ends, we print the results to the Transcript:

VW Receives

VA Sends/Receives

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u252-iPhone.m4v ( Size: 4566368 )]

posted by James Robertson

 Share Tweet This