⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 it bout file transfer this is about client and server
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace Server
{
    class Program
    {
        static NetworkStream nStream;
        static StreamReader readImageData;

        static StringBuilder BlockData = new StringBuilder();
        static bool Done=false;

        static void Main(string[] args)
        {
            byte[] IpByte = { 127, 0, 0, 1 };
            IPAddress ipAddress = new IPAddress(IpByte);
            TcpListener tcpListener = new TcpListener(ipAddress, 5555);
            tcpListener.Start();
            Console.WriteLine("Server Started");

            TcpClient tcpClient = tcpListener.AcceptTcpClient();
            Console.WriteLine("Connection Made");
            nStream = tcpClient.GetStream();
            readImageData = new StreamReader(nStream);

            string data;

            while (Done==false)
            {
                while ((data= readImageData.ReadLine()) != null)
                {
                     BlockData.Append(data);
                }

                Done = true;
            }
            byte[] byte_image = Convert.FromBase64String(BlockData.ToString());

            // Change File Name Here 
            FileStream fs = new FileStream("logo.jpg", FileMode.Create);
            fs.Write(byte_image, 0, byte_image.Length);
            fs.Flush();
            Console.WriteLine("Check the Debug folder in the Server Project to see the transfered file.");
            Console.ReadKey();

            readImageData.Close();
            tcpClient.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -