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 typically used to requests data from an Internet resource using TCP (Transmission Control Protocol).

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 last byte time-out, 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). By default, to detect the last byte received, the method will wait until the value of the field _LastByteTimeOut as time-out time. If a positive number (lastByte) is specified as left argument, the method will return as soon as this byte is received. Alternatively a negative number can be specified as left argument (qtyBytes) and the method will return as soon as this quantity of bytes as been received. Those 2 previous options will make the communication much faster when they are used.

     r ←          com.Send bytes  ⍝ bytes = numbers from 0 to 255
     r ← lastByte com.Send bytes  ⍝ lastByte = positive number
     r ← qtyBytes com.Send bytes  ⍝ qtyBytes = negative number

     ⍝ 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 ← com.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