Differences between revisions 2 and 3
Revision 2 as of 2015-12-27 00:22:15
Size: 3207
Comment: Under Construction
Revision 3 as of 2015-12-29 22:05:27
Size: 2732
Comment: UNDER CONSTRUCTION
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
'''TCP''' is a Dyalog cover class for Asynchronous TCP/IP Communication using the .Net [[https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient%28v=vs.110%29.aspx|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). '''TCP''' is a Dyalog cover class for Asynchronous TCP/IP Communication using the .Net [[https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient%28v=vs.110%29.aspx|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.
Line 12: Line 12:
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). 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).
Line 23: Line 23:
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. 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.
Line 25: Line 25:
     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 ← tcp.Send bytes ⍝ bytes = numbers from 0 to 255
Line 35: Line 33:
     r ← com.Close      r ← tcp.Close

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

netTCP (last edited 2016-01-09 23:22:08 by PierreGilbert)