如何用Socket编程传递Word文件?
纯文本文件容易传,但Word,Excel文件怎么办?注意里面不光是只有文字,可能还有表格,图片什么的。本人代码如下,但似乎不行。接收后打开是乱码。
System.Net.Sockets.Socket lskt_Socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
System.Net.IPEndPoint liep_IPEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse( "127.0.0.1 "), 9999);
System.IO.FileStream lfs_FileStream = new System.IO.FileStream(this.tbx_FileName.Text.Trim(), System.IO.FileMode.Open);
byte[] larr_FileData = new byte[lfs_FileStream.Length];
lfs_FileStream.Read(larr_FileData, 0, larr_FileData.Length - 1);
lskt_Socket.Connect(liep_IPEndPoint);
lskt_Socket.Send(larr_FileData);
lfs_FileStream.Close();
lskt_Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
lskt_Socket.Close();
System.Windows.Forms.MessageBox.Show( "文件发送成功! ");
------解决方案--------------------关注
个人觉的 应该是一样的啊
传文件 就是 文件
------解决方案--------------------关注