      SUBROUTINE PLX.TCP.WRITE(R.PLCB,OPT,MAX.TIME,SSTR,R.ERR)
*PIC-LAN
*
*ALL
*PC
*N
*
*
*
*
      INCLUDE SYS.TYPE.INCLUDE
*
      INCLUDE PL.DEFS
      DIM CONFIG.ARRAY(50)
      INCLUDE PL.COMMON.DEFS
*
      DIM PLIP$VARS(100)
      INCLUDE PLIP.VARS
*
      CALL PLXX.INIT(MAT CONFIG.ARRAY,MAT PLIP$VARS,0)
*
      RESOURCE.LIST = ''
*
      OPT = OCONV(OPT,'MCU')
      X.OPT = ( INDEX(OPT,'X',1) <> 0 )
*
      R.STR = ''
      R.LEN = 0
      R.STATUS = ''
      R.ERR = ''
*
      T0 = PL_NOW()
      LOOP
         NW = PL_NOW()
         IF NW < T0 THEN T0 = NW
         IF NW - T0 > 120 THEN T0 = NW - 120
*
         CALL PLXX.TCP.STATUS(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB,ST,R.ERR)
         IF R.ERR <> '' THEN RETURN
*
         IF ST <= 1 OR ST >= 11 THEN
            R.ERR = 'TCP connection closed'
            CALL PLXX.TCP.RESET(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB)
            RETURN
         END
*
         IF X.OPT THEN
            D = SSTR[1,( PLIP$MAX.IO.LEN * 2 )]
            PL_WRITEX D ON R.PLCB ELSE
               R.ERR = 'Error during TCP write'
               CALL PLXX.TCP.RESET(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB)
               RETURN
            END
         END ELSE
            D = SSTR[1,PLIP$MAX.IO.LEN]
            PL_WRITE D ON R.PLCB ELSE
               R.ERR = 'Error during TCP write'
               CALL PLXX.TCP.RESET(MAT CONFIG.ARRAY,MAT PLIP$VARS,R.PLCB)
               RETURN
            END
         END
*
         IF NOT(RES) THEN
            IF PL_NOW() - T0 >= MAX.TIME THEN RETURN
         END ELSE
            IF X.OPT THEN
               SSTR = SSTR[RES*2+1,BIG.STR]
            END ELSE
               SSTR = SSTR[RES+1,BIG.STR]
            END
            IF SSTR = '' THEN RETURN
         END
      WHILE 1 DO REPEAT
   END
