Alchemy Websockets& VB.NET [英] Alchemy Websockets & VB.NET

查看:138
本文介绍了Alchemy Websockets& VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VB.NET构建Alchemy Websockets服务器。我已经在C#中获取了示例代码,用于设置服务器的新实例并通过C#转换为VB转换器。





ORGINAL C#代码: -



I am trying to build an Alchemy Websockets server with VB.NET. I have taken the sample code, in C#, for setting up a new instance of the server and ran it though a C# to VB converter.


ORGINAL C# CODE:-

{
  // instantiate a new server - acceptable port and IP range,
  // and set up your methods.

  var aServer = new WebSocketServer(81, IPAddress.Any) {
    OnReceive = OnReceive,
    OnSend = OnSend,
    OnConnect = OnConnect,
    OnConnected = OnConnected,
    OnDisconnect = OnDisconnect,
    TimeOut = new TimeSpan(0, 5, 0)
  };

  aServer.Start();
}





转换后: -





AFTER CONVERSION:-

Dim aServer = New WebSocketServer(81, IPAddress.Any) With { _
    Key .OnReceive = OnReceive, _
    Key .OnSend = OnSend, _
    Key .OnConnect = OnConnect, _
    Key .OnConnected = OnConnected, _
    Key .OnDisconnect = OnDisconnect, _
    Key .TimeOut = New TimeSpan(0, 5, 0) _
}

aServer.Start()





这不起作用,它没有链接Key,所以,这就是我最终的结果: -





This doesn't work, it doesn't link the "Key", so, this is how I've ended up:-

__aServer = New WebSocketServer(8181, IPAddress.Any)
With __aServer
  .OnConnect = New OnEventDelegate(AddressOf OnUserConnect)
  .OnDisconnect = New OnEventDelegate(AddressOf OnUserDisconnect)
  .OnReceive = New OnEventDelegate(AddressOf OnDataReceive)
  .OnSend = New OnEventDelegate(AddressOf OnDataSend)
  .TimeOut = New TimeSpan(0, 5, 0)
End With
__aServer.Start()







这似乎通过了语法检查,代码运行正常,但是,唯一要触发的事件是OnConnect。因此,当我从客户端向服务器发送数据时,没有任何东西发生。



有人可以为我点亮这个吗?



问候



Mark




This seems to pass a syntax check, and the code runs ok, but, the only event to fire is the "OnConnect". So when I send data from the client to the server, nothing fires.

Can anyone throw some light on this for me?

Regards

Mark

推荐答案

好吧,乍一看对象初始化器格式不正确。怎么样:



Well, at first glance the object initializer isn't formatted correctly. How about this:

Dim aServer = New WebSocketServer(81, IPAddress.Any) With { _
     .OnReceive    = OnReceive,
     .OnSend       = OnSend,
     .OnConnect    = OnConnect,
     .OnConnected  = OnConnected,
     .OnDisconnect = OnDisconnect,
     .TimeOut      = New TimeSpan(0, 5, 0)
}
aServer.Start()





此外,查看您的修复程序,您正在创建新的OnEventDelegates。您是否尝试过简单地传递每个AddressOf yourCallbackSub?即:





Also, looking at your fix, you are creating new OnEventDelegates. Have you tried simply passing each one AddressOf yourCallbackSub? Ie:

Dim aServer = New WebSocketServer(81, IPAddress.Any) With { _
     .OnReceive    = AddressOf OnDataReceive,
     .OnSend       = AddressOf OnDataSend,
     .OnConnect    = AddressOf OnUserConnect,
     .OnConnected  = AddressOf ?, ' You left this one out of your fix. This could be your missing event...
     .OnDisconnect = AddressOf OnUserDisconnect,
     .TimeOut      = New TimeSpan(0, 5, 0)
}
aServer.Start()





- 皮特



- Pete


这篇关于Alchemy Websockets& VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆