Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day,

I want to write simple websocket client uisng .net application. Mainly this will work as Google - Simple WebSocket Client Extension.

Please help if possible.

Thanks in advance.

Regards,
YRishi

What I have tried:

I tried below code but getting error - System.Net.Internals.SocketExceptionFactory.ExtendedSocketException: 'No connection could be made because the target machine actively refused

Code as belwo.
C#
TcpClient client = new TcpClient();

     client.Client.Connect(IPAddress.Parse("xx.xx.xx.xx"), 8000);

     //Task.Run(() =>; ReadData(client));

     Task.Run(() =>; ReadDataLoop(client));

     client.Client.Send(Encoding.ASCII.GetBytes("{\"TID\":1111,\"blabla\":{}}"));
Posted
Updated 23-Oct-19 8:07am
v3

xx.xx.xx.xx is not a valid IP address.

But if you look carefully at the error message you can see the problem. Whatever system you are trying to connect to will not accept your connection request. So you need to find out from the owners of that site why that is. Is it an open system that allows anonymous connections, or does it require authorisation details?
 
Share this answer
 
Comments
yrishi 23-Oct-19 8:46am    
Hi Richard

Thanks for your reply.

IP is correct and I've done it consciously :)

Yes it is an open system as my system and that IP address is on same LAN.

Regards,
Yogesh
Richard MacCutchan 23-Oct-19 10:56am    
Then you should easily be able check that you can connect to it from a browser, or telnet session
Most probably, the firewall on the target machine is not accepting incoming TCP connections on port 8000.
 
Share this answer
 
Comments
yrishi 23-Oct-19 9:03am    
Thanks Phil.o for your reply. IP is correct. Let me check with firewall settings.
Try to add port 8000 in Windows as described here: How to Allow Apps to Communicate Through the Windows Firewall[^]
 
Share this answer
 

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