I am porting some code from QT in .NET. I am using VS2019 Pro and need to capture WebSocketClient
events as a message received.
I have this:
using System;
using System.Linq;
using System.Net.WebSockets;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DevWebSockets{
public delegate void OnDev_TxtMsgRcvd(object sender,EventArgs e);
class Program {
public enum WebSocketConnectionState {
SockNotConnected, SockEstablishingConnection, SockConnected
}
public WebSocketConnectionState m_ConnectionState;
public event OnDev_TxtMsgRcvd DevTxtRcvdEvent; // OnTxtMsgRcvd;
public void OnDev_TxtMsgRcvd(object sender, EventArgs e) {
Console.WriteLine("Dev - Rcvd Text message");
}
static void Main(string[] args) {
try {
new Program().Start().Wait();
} catch (Exception ex) {
// Console.WriteLine("Exception {0} - {1}", ex.Message, ex.InnerException);
}
}
public async TaskStart(){
m_ConnectionState = WebSocketConnectionState.SockNotConnected;
Console.WriteLine("Press enter to start Please ");
string name = Console.ReadLine();
Console.WriteLine("Connecting...");
var cts = new CancellationTokenSource();
var CWS = new ClientWebSocket();
CWS += new EventHandler<ClientWebSocket>(OnDev_TxtMsgRcvd(Object s, EventArgs e));
}
}
}
At this point the compiler has placed a
CS1525 - Invalid expression term 'object' for the word Object
CS1003 - Syntax error ',' expected under the letter s
CS1003 - Syntax error ',' expected under the letter e
Hovering on the red squiggly lines produces:
object
is a type which is not valid in the given context
- The one under 's' says: The name 's' does not exist in the current context
- The one under
EventArgs
is the same as the one under object - The one under 'e' is the same as the one under 's'
Basically I want to have a method to catch messages incoming from the device so I can determine actions to be taken if any.