TCP送信

TCP送信

PowerShell

参考

スクリプト

# 
# TCP送信
# https://qiita.com/LazarusMakoto/items/631af8aba4079f82c7c3
# 
# コマンドプロンプトで
# powershell -ExecutionPolicy RemoteSigned -File socket_client.ps1
# 

while ($TRUE)
{
  $soc = New-Object System.Net.Sockets.tcpClient
  $soc.connect("192.168.0.1", 80) # ポート番号はサーバプログラムにあわせる
  
  # 同じTCPコネクション内でループ
  while ($TRUE)
  {
    try {
      sleep -m 200 # 待機(ミリ秒)
      $sendData=cat -en by "sample2.bin" # ファイルから送信データを読み込み
      $soc.GetStream().Write($sendData, 0, $sendData.Length)
      $now= Get-Date -Format "yyyy/MM/dd HH:mm:ss.fff"
      echo "[$now] 送信成功"
    } catch {
      break
    }
  }
  
  $now= Get-Date -Format "yyyy/MM/dd HH:mm:ss.fff"
  echo "[$now] エラー、リトライ .."
  $soc.close()
}

$soc.close()