作为我教育项目的一部分,我正在测试几种.net实时通信方法.其中一个是信号灯.出于这个原因,我有两个程序:
这些程序的典型工作流程是:启动服务器 - >使用ClientHostApp-> run tests连接一些客户端.
如果程序同时托管在同一台计算机上,但如果尝试在不同的计算机上运行程序,则会出现问题.特别是,我无法从单个ClientHostApp实例连接多个客户端.
服务器代码:
//starting up the server
public override void Start()
{
string url = "http://*:9523/MessagingServiceHostWPF/";
Server = new SignalR.Hosting.Self.Server(url);
Server.MapHubs();
Server.Start();
}
Run Code Online (Sandbox Code Playgroud)
...
//one of the methods inside the hub exposed by the server
public DataContracts.ClientInfo AcknowledgeConnection(string handle)
{
ServerLogic.DataContracts.ClientInfo clientInfo = SignalRApplicationState.SingletonInstance.AddClient(handle, Context.ConnectionId);;
return clientInfo;
}
Run Code Online (Sandbox Code Playgroud)
ClientHostApp:
//starting many clients in a loop
foreach (var client in _clients)
{
client.Start();
}
Run Code Online (Sandbox Code Playgroud)
...
//method inside the Client class
public async void Start() …Run Code Online (Sandbox Code Playgroud) 我试图使用以下代码从ftp服务器下载文件:
using (System.IO.FileStream fileStream = System.IO.File.OpenWrite(filePath))
{
byte[] buffer = new byte[4096];
int bytesRead = responseStream.Read(buffer, 0, 4096);
while (bytesRead > 0)
{
fileStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, 4096);
}
}
Run Code Online (Sandbox Code Playgroud)
responseStream的创建:
System.IO.Stream responseStream = GetFileAsStream(url, username, password, false);
public static System.IO.Stream GetFileAsStream(string ftpUrl, string username, string password, bool usePassive)
{
System.Net.FtpWebRequest request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpUrl);
request.KeepAlive = false;
request.ReadWriteTimeout = 120000;
request.Timeout = -1;
request.UsePassive = usePassive;
request.Credentials = new System.Net.NetworkCredential(username, password);
request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
System.IO.Stream fileResponseStream;
System.Net.FtpWebResponse …Run Code Online (Sandbox Code Playgroud) 我是javascript的新手,我需要你的帮助,将谷歌地图设置为div元素,这是另一个div元素.这是在div元素未嵌套时有效的代码:
function initialize() {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
Run Code Online (Sandbox Code Playgroud)
但是,如果我有嵌套的div,它不起作用:
<body onload="initialize()">
<div id="main">
<div id="map_canvas" style="width:100%; height:100%"></div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
在 .NET 4.5 中,引入了新的 WCF 绑定 NetHttpBinding,它使用 WebSocket 协议作为其底层传输。这意味着这可以实现来自服务器的真正推送。现在,我已经能够使用回调合约进行某种推送,如下所示:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class WebSocketSampleService : IDuplexContract
{
public string SayHelloDuplex()
{
//push to the current caller
OperationContext.Current.
GetCallbackChannel<IDuplexCallbackContract>().
SayingHello("Hello from WebSockets");
//answer the current caller in the regular http way
return "Hello";
}
}
[ServiceContract(CallbackContract=typeof(IDuplexCallbackContract))]
public interface IDuplexContract
{
[OperationContract]
string SayHelloDuplex(string name);
}
[ServiceContract]
public interface IDuplexCallbackContract
{
[OperationContract]
void SayingHello(string message);
}
Run Code Online (Sandbox Code Playgroud)
不过,我想做的是,当单个客户端调用该方法时,将消息广播给所有客户端SayHelloDuplex()。有没有办法访问所有客户端的回调通道?或者我应该记录所有客户端的回调通道以供以后在其他方法中使用(例如Connect())?也许我以错误的方式解决这个问题?
任何帮助将不胜感激。谢谢
是否可以将SIP请求记录到星号中的数据库?我对这些细节很感兴趣:
我很确定可以将queue_log事件转换为SIP请求并从中获取上述信息.但是,由于并非所有呼叫都通过呼叫队列,因此此解决方案对我不起作用.
也许通过使用AMI可以实现?或者写自定义拨号方案?请分享您对此问题的看法.