닷넷의 XSocket을 처음 접했습니다.XSockets.Net으로 대용량 파일 보내기
내 서버 코드는 다음과 같습니다. 다음
public class MyChatController : XSocketController
{
public void Foo(ITextArgs textArgs)
{
this.SendToAll(textArgs);
}
}
는 클라이언트 측 코드
static void Main(string[] args)
{
var client = new XSocketClient("ws://127.0.0.1:4502/MyChat","*");
client.OnOpen += (sender, eventArgs) => Console.WriteLine("OPEN");
client.Bind("foo", message=>
{
dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(message.data);
var array = data;
byte[] bytes = Convert.FromBase64String(array);
Stream readStream = new MemoryStream(bytes);//videovm.video
var fileName = "C:\\Users\\NandaKishore\\Documents\\Visual Studio 2013\\Projects\\CSClientApp\\CSClientApp\\somefile" + ".mp4";
string targetPath = fileName;
FileStream writeStream = new FileStream(targetPath, FileMode.Create, FileAccess.Write);
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
Console.WriteLine("done dona done");
});
client.Open();
ConsoleKeyInfo cki;
Console.WriteLine("Press the Escape (Esc) key to quit and any other key to send a message: \n");
var _FileName = "C:\\Users\\NandaKishore\\Documents\\Visual Studio 2013\\Projects\\CSClientApp\\CSClientApp\\tt.mp4";
byte[] _Buffer = null;
try
{
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
do
{
cki = Console.ReadKey();
if (cki.Key != ConsoleKey.Escape) {
var dd = Convert.ToBase64String(_Buffer);
client.Send(dd, "foo");
}
} while (cki.Key != ConsoleKey.Escape);
}
그것은 작은 이미지와 동영상에 대한 잘 작동하지만 큰 비디오와 함께 실패합니다. 바이트 서비스 또는 기타와 같은 대용량 파일을 전달하는 더 좋은 방법이 있습니까?
모든 안내가 도움이 될 것입니다.