「東雲 忠太郎」の平凡な日常のできごと

「東雲 忠太郎」の平凡な日常のできごと

2024.02.25
XML
カテゴリ: VB.NET


using System;

using System.Net;

using System.Net.Sockets;

using System.Text;


class Program

{

    static void Main(string[] args)

    {

        // 25番ポートを監視する

        int port = 25;

        TcpListener listener = new TcpListener(IPAddress.Any, port);

        listener.Start();


        Console.WriteLine("Waiting for connections...");


        while (true)

        {

            // クライアントからの接続を待機

            TcpClient client = listener.AcceptTcpClient();

            Console.WriteLine("Connected to client.");


            // ネットワークストリームを取得してデータを読み取る

            NetworkStream stream = client.GetStream();

            byte[] buffer = new byte[client.ReceiveBufferSize];

            int bytesRead = stream.Read(buffer, 0, buffer.Length);


            // データを文字列に変換して表示

            string dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead);

            Console.WriteLine("Data received: " + dataReceived);


            // 接続を閉じる

            client.Close();

        }

    }

}







お気に入りの記事を「いいね!」で応援しよう

Last updated  2024.02.25 09:26:17


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

© Rakuten Group, Inc.
Create a Mobile Website
スマートフォン版を閲覧 | PC版を閲覧
Share by: