UNDER CONSTRUCTION

TCP

Overview

TCP is a Dyalog cover class for Asynchronous TCP/IP Communication using the .Net TcpClient object. It is using the methods WriteAsync and ReadAsync available with .Net 4.5 for asynchronous communication that will not block the calling thread during the communication process. It is used to requests data from an Internet resource using TCP (Transmission Control Protocol) over IP (Internet Protocol) like for home automation, data acquisition and process control.

Typical Usage

Instantiating the class

      tcp ← ⎕NEW TCP

Connecting to a Remote Host

The TCP protocol establishes a connection with a remote endpoint and then uses that connection to send and receive data packets. TCP is responsible for ensuring that data packets are sent to the endpoint and assembled in the correct order when they arrive. The Connect method is used to establish this connection. In the class you can specify the buffer size, the port time-out, the switching delay as fields (see their individual comments in the class for more information).

      r ← tcp.Connect(ip port)

    ⍝ ip    = IP Address where to send the bytes in characters ('192.168.1.1') or numbers (192 168 1 1)
    ⍝ port  = Port Number to send the bytes (0 - 65535).

    ⍝ r[1] = 1 for Success, 0 for Failure
    ⍝ r[2] = Literal Error if Failure

Sending the Data

The method Send is used to send the data as numbers from 0 to 255 (bytes). The response contains the data received. To convert characters to bytes use ⎕UCS to do the conversion.

     r ← tcp.Send bytes  ⍝ bytes = numbers from 0 to 255

     ⍝ r[1] = 1 for Success, 0 for Failure
     ⍝ r[2] = Response if Success, Literal Error if Failure

Closing the Connection

The method Close is used to close the connection.

     r ← tcp.Close

     ⍝ r[1] = 1 for Success, 0 for Failure
     ⍝ r[2] = Literal Error if Failure

How to install TCP in your workspace

  1. Download TCP.v1.0.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ○ TCP

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Version Information

 Version 1.0 December 2016, Pierre Gilbert

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


CategoryDyalog - CategoryDyalogDotNet - CategoryDotNet