To define the server, you use nonvisual parts in the VisualAge: Communications, TCP feature. The example uses a TCP Socket part to listen for and send messages from the database parts.
Begin by adding a nonvisual part named, for example, MyServer, to MyDatabaseTCPIPApp. (To simplify this example, the client and server code are both in MyDatabaseTCPIPApp. To package and deploy this example, you must create a separate application to hold the code for the TCP/IP server.)
Go to the Public Interface Editor and add two attributes: one attribute, data, uses a String data type; and the other, clientSocket, uses an AbtSocket data type. Next, add two events, startServer and endServer, and add then with their defaults.
Go to the Composition Editor and do the following:
SELECT * FROM STAFF WHERE (STAFF.ID = :id)
Go to the Script Editor and add the following methods. Add the class method startServer:
startServer "Set the port. This example uses 2012 though you can you any port number." (MyServer new) startServerOnPort: 2012.
Then add four instance methods:
acceptAndReceive self clientSocket: (self subpartNamed: 'serverSocket') value accept. self clientSocket bufferLength: 4098. self data: (self clientSocket receiveWithLengthInData) contents.
connectAndRunQuery | dbm dsn logonSpec spec conn rt rowAsString | (AbtDbmSystem activeDatabaseConnectionWithAlias: 'serverAlias') isNil ifTrue: [ dbm := (AnAcessSet serverAlias) dbmClass. dsn := (AnAcessSet serverAlias) dsn. logonSpec := AbtDatabaseLogonSpec id: ((self subpartNamed: 'dbRcd') abtAtAttribute: #userid) password: ((self subpartNamed: 'dbRcd') abtAtAttribute: #password) server: dsn. spec := (AbtDatabaseConnectionSpec forDbmClass: dbm dataSourceName: dsn) promptEnabled: false. conn := spec connectUsingAlias: 'serverAlias' logonSpec: logonSpec. ((AbtDbmSystem activeDatabaseConnectionWithAlias: 'serverAlias') isNil) ifTrue: [ (self subpartNamed: 'clientSocket of MyServer') abtPerformAction: #sendIncorporatingLength: with: (self subpartNamed: 'dbRcd') data ]. ].
(self subpartNamed: 'Multi-row Query1') executeQueryAsTransaction. rt := (self subpartNamed: 'resultTable of Multi-row Query1') value. rowAsString := (rt rows) collect: [:aRow| aRow asString ]. ( rowAsString isEmpty ) ifFalse: [ (self subpartNamed: 'dbRcd') abtAtAttribute: #results put: (rowAsString at: 1). ]. (self subpartNamed: 'clientSocket of MyServer') abtPerformAction: #sendIncorporatingLength: with: (self subpartNamed: 'dbRcd') data. (self subpartNamed: 'clientSocket of MyServer') abtPerformAction: #disconnect
portNumber ^2012
startServerOnPort: aPort (self subpartNamed: 'serverSocket') value: (AbtSocket serverSocketOnPort: aPort). self acceptAndReceive.
Return to the Composition Editor and make the following connections:
When you finish, the Composition Editor shows: