Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the TclClient and Stream from iWebSocketConnection #310

Open
nsmith1024 opened this issue Apr 5, 2021 · 1 comment
Open

How to get the TclClient and Stream from iWebSocketConnection #310

nsmith1024 opened this issue Apr 5, 2021 · 1 comment

Comments

@nsmith1024
Copy link

nsmith1024 commented Apr 5, 2021

Hello,

Im upgrading my old C# server code from using regular TCP Sockets, to using your secure WebSocket (wss://)

My old code looks like this

TcpListener serverSocket;
....
TcpClient client = serverSocket.AcceptTcpClient();
Stream stream = new SslStream(client.GetStream(), false);

My old code uses "client" and "stream" variables from above in literally a million places. So im wondering if your WebSocket class has some equivalent to theses so that i dont have to rewrite all my code? Im starting off using your example like this below

var server = new WebSocketServer("wss://0.0.0.0:8431");
server.Certificate = new X509Certificate2("MyCert.pfx");
server.Start(socket =>
{
TclClient client=socket.client; <---- Do you have this??
Stream stream=socket.stream; <---- Do you have this???
// send and receive on the stream
});

Do you have a way where i can obtain the TcpClient and Stream from your "socket" iWebSocketConnection variable above?

Thanks

@GinCanhViet
Copy link

server.Start(socket =>
{
    var connectionInfo = socket.ConnectionInfo; <--- All info you can get
    socket.OnOpen = () => OnOpen(connectionInfo);
    socket.OnClose = () => Console.WriteLine("Close!");
    socket.OnMessage = message => socket.Send("You said: " + message);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants