[英]How to Send File to SignalR hub From websocket-sharp Client?
We are using the websocket-sharp in one of our applications which establishes a websocket connection with our SignalR Hub on the server, we are able to send the text messages and receive the response for the same but unable to post a byte[]
. 我们正在其中一个应用程序中使用websocket-sharp,该应用程序与服务器上的SignalR Hub建立了websocket连接,我们能够发送文本消息并接收相同的响应,但无法发布
byte[]
。
Code for sending text to server is this: 用于向服务器发送文本的代码是这样的:
public void TestGroupData(string groupname)
{
DataCarrier dataCarrier = new DataCarrier()
{
H = "BILHub",
M = "GetAllGroupsFor",
A = new string[] { groupname }
};
string wsPacket = JsonConvert.SerializeObject(payLoad);
this._ws.Send(wsPacket);
//this.MakeServerCall(dataCarrier);
}
When we try to send byte[]
using the below code, its not going through: 当我们尝试使用以下代码发送
byte[]
,它没有通过:
public void TestFileData()
{
try
{
// Read the file data
Console.WriteLine("Started reading file");
string fileName = @"C:\Saurabh\Data\Song.mp3";
byte[] file = File.ReadAllBytes(fileName);
DataCarrier dataCarrier = new DataCarrier()
{
H = "BILHub",
M = "SendFile",
A = new object[] { file }
};
string wsPacket = JsonConvert.SerializeObject(dataCarrier);
this._ws.SendAsync(file , OnSendComplete);
}
catch (Exception ex)
{
Console.WriteLine(ex);
//throw;
}
}
Any help with this? 有什么帮助吗? How can I set my hub name in
_ws.sendAsync()
? 如何在
_ws.sendAsync()
设置集线器名称?
Sending big files is not really what SignalR is meant for. 发送大文件并不是SignalR真正的目的。
SignalR is good for real-time messaging purposes between server & clients, for a rather small sized messages (as messahe size has a real impact on performance ). SignalR非常适合服务器与客户端之间的实时消息传递 ,对于较小的消息(因为消息传递的大小会对性能产生实际影响 )。
For such a need I would look into ASP.NET Web API, especially by using chunked upload (splitting file in multiple pieces to avoid connection interruptions) 为此,我将研究ASP.NET Web API,特别是通过使用分块上传 (将文件拆分为多个文件以避免连接中断)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.