Managing TCP Connections

The TCP activities are designed to work with custom applications that communicate with other applications via TCP. This sample shows how to perform common tasks, such as opening a connection, writing data to it, and closing the connection.

Procedure

  1. In the samples directory, select palette > tcp > Basic and double-click tibco.bw.sample.palette.tcp.Basic. For more information, see Accessing Samples.
  2. In the Project Explorer view, expand the tibco.bw.sample.palette.tcp.Basic project.
  3. Set the default ApplicationProfile to match the OS you are running on. For more information, see Setting the Default Application Profile.
  4. Fully expand the Processes directory. See multiple sample sub packages, each comprising a Client.bwp and Server.bwp process. Double-click each process to view the activities defined.
  5. Click Run > Debug Configurations.
  6. At the left hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  7. Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the check box next to tibco.bw.sample.palette.tcp.Basic.application.
  8. Click Debug.
    This runs the sample in Debug mode.
  9. Click the Terminate icon to stop the process.

Result

The TCP_Basic.log file is generated at C:\tmp\TCP_Basic contains the following data.

Test Request Data by iterationLoop- 1

Test Request Data by iterationLoop- 2

Test Request Data by iterationLoop- 3

Test Request Data by iterationLoop- 4

Test Request Data by noSeparator

Test Reply Data by noSeparator

Test Request Data by preDefinedSeparator

Test Reply Data by preDefinedSeparator

Test Request Data by userDefinedSeparator

Test Reply Data by userDefinedSeparator

Test Request Data by binarySeparator

Test Reply Data by binarySeparator

The Console view displays the output similar to the following.

10:40:20.505 INFO [bwThread:In-Memory STWorkProcessor-1] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by iterationLoop- 1

10:40:20.545 INFO [bwThread:In-Memory STWorkProcessor-5] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by iterationLoop- 2

10:40:20.568 INFO [bwThread:In-Memory STWorkProcessor-7] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by iterationLoop- 3

10:40:20.593 INFO [bwThread:In-Memory STWorkProcessor-8] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by iterationLoop- 4

10:40:20.618 INFO [bwThread:In-Memory STWorkProcessor-2] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest -

10:40:21.447 INFO [bwThread:In-Memory STWorkProcessor-1] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by noSeparator

10:40:21.491 INFO [bwThread:In-Memory STWorkProcessor-7] c.t.b.p.g.L.t.b.s.p.t.B.PrintReply - Test Reply Data by noSeparator

10:40:22.428 INFO [bwThread:In-Memory STWorkProcessor-4] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by preDefinedSeparator

10:40:22.460 INFO [bwThread:In-Memory STWorkProcessor-3] c.t.b.p.g.L.t.b.s.p.t.B.PrintReply - Test Reply Data by preDefinedSeparator

10:40:23.429 INFO [bwThread:In-Memory STWorkProcessor-2] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by userDefinedSeparator

10:40:23.445 INFO [bwThread:In-Memory STWorkProcessor-6] c.t.b.p.g.L.t.b.s.p.t.B.PrintReply - Test Reply Data by userDefinedSeparator

10:40:24.429 INFO [bwThread:In-Memory STWorkProcessor-7] c.t.b.p.g.L.t.b.s.p.t.B.PrintRequest - Test Request Data by binarySeparator

10:40:24.467 INFO [bwThread:In-Memory STWorkProcessor-8] c.t.b.p.g.L.t.b.s.p.t.B.PrintReply - Test Reply Data by binarySeparator

Understanding the Configuration

The following TCP palette activities are used in this sample:

  • TCP Receiver: The process starter starts a new process, when a client requests a TCP connection.
  • Wait for TCP Request: The activity waits for a TCP client connection request.
  • TCP Open Connection: The activity opens a connection to a TCP server.
  • TCP Close Connection: The activity closes a TCP connection opened by a previously executed activity or process starter.
  • Write TCP Data: The activity sends data on the specified TCP connection.
  • Read TCP Data: The activity reads data from an open TCP connection.

The processes show the use of Binary and Text modes.

Binary mode:
  • The binarySeparator sub-package shows the use of user-defined binary separator in binary mode.
  • The iterationLoop sub-package shows the use of an iteration loop.
  • The noSeparator sub-package shows the use of no separator in binary mode.
Text mode:
  • The preDefinedSeparator sub-package shows the use of a pre-defined text separator in text mode.
  • The userDefinedSeparator sub-package shows the use of a user-defined text separator in text mode.