it bout file transfer this is about client and server

源代码在线查看: program.cs

软件大小: 81 K
上传用户: yhb71181491615
关键词: transfer client server about
下载地址: 免注册下载 普通下载 VIP

相关代码

				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();
				        }
				    }
				}
							

相关资源