Esempio n. 1
0
        /// <summary>
        /// 尝试让服务器转发一个文件,
        /// </summary>
        /// <param name="FileName">文件地址</param>
        /// <param name="FromNum">来自</param>
        /// <param name="ToNum">去往</param>
        /// <param name="PacketType">数据包类型</param>
        /// <param name="PrintFileName">输出后的文件名称</param>
        /// <returns>传过去的大小</returns>
        public static long TCPSendFile(String FileName, long FromNum, long ToNum, DataPacketType PacketType, out String PrintFileName)
        {
            Socket SocketBuffer = new Socket(SocketType.Stream, ProtocolType.Tcp);

            SocketBuffer.Connect(StaticResource.ServerIpaddress);
            long   res          = 0;
            String DateFileName = DateTime.Now.Ticks + IoTool.GetFileType(FileName);

            //String DateFileName = StaticResource.DateTimeLoginNumber(FromNum) + IoTool.GetFileType(FileName);
            IoTool.GetFileByteBlockALL(FileName, (int)DefaultMaxDataPacketSize, (content, filenmae, islast, count) =>
            {
                MessageModel msg = new MessageModel()
                {
                    FromIpaddress   = IPV4Address.ToString(),
                    FromLoginNumber = FromNum,
                    ToLoginNumber   = ToNum,
                    MessageType     = MessageType.DataPacket,
                    SendDateTime    = DateTime.UtcNow.ToString(),
                    MessageContent  = new MessageContent_DataPacket(content, DateFileName, islast, count, PacketType),
                };
                res += SocketBuffer.Send(MessageModel.ToBytes(msg));
                Thread.Sleep(50);
            });
            SocketBuffer.Close();
            SocketBuffer.Dispose();
            PrintFileName = DateFileName;
            return(res);
        }
Esempio n. 2
0
        public static bool SendFile(String FileName, EndPoint TargetIP)
        {
            Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp);

            client.Connect(TargetIP);
            IoTool.GetFileByteBlockALL(FileName, (int)DefaultMaxDataPacketSize, (bs, str, boo, inti) =>
            {
                client.Send(bs);
                if (boo)
                {
                    client.Close();
                    client.Dispose();
                }
            });
            return(true);
        }