Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I would like to ask of anyone ever wrote web socket client in C# as e.g. console application. I did find some external libraries but either they had no SSL support or it didn't make any difference. I'm using .NET 3.5 and I can't change it. Unfortunately my client is using WebSocket and I have no other choice.
Posted
Comments
Sergey Alexandrovich Kryukov 14-Jan-15 14:44pm    
Not clear. And not really a question. Why finding "external library"? Why searching or someone who "ever wrote Web socket". Why not sitting down and writing what you need using MSDN documentation? Any problems?
—SA
geo_m 15-Jan-15 8:53am    
Isn't WebSocket supported only since net4.5?
Kurkey 15-Jan-15 8:56am    
Yeah native support for WebSocket is available since .NET 3.5. Thats why I'm looking for good external library for .NET 3.5 so it possibly could work with mono.

1 solution

To send requests and receive responses you can use:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);


where url is the query string "https://...".

The main difference with SSL is you must verify the certificate:

C#
//before any request you need this only once in your code
//you can put in beginning of you app

RemoteCertificateValidationCallback remote = ValidateServerCertificate;
ServicePointManager.ServerCertificateValidationCallback = remote;
                

public bool ValidateServerCertificate(
            object sender,
            X509Certificate certificate, 
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors)
        {
            return true; //always accept... really should check it
        }
 
Share this answer
 
Comments
Kurkey 15-Jan-15 16:49pm    
Thanks for that. However this is creating https web request. Whereas WebSocket uses wss:// url.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900