1 Replies - 128 Views - Last Post: 10 February 2020 - 10:44 AM Rate Topic: -----

#1 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 493
  • Joined: 13-September 15

Basic websocket listener not working

Posted 10 February 2020 - 10:16 AM


I want to write a piece of code which listens on everything that comes in on a specific port on my localhost, and outputs it.

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse(""), 5050);


            while (true) {
                byte[] buffer = new byte[1024];
                int rec = socket.Receive(buffer);


Unhandled exception. System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (61): Connection refused
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at HelloWorld.Program.Main(String[] args) in /Users/niel/School/C#_Onderzoekstopic/tests/HelloWorld/Program.cs:line 16

I just want this code to work and output everything I write in the telnet 5050 commando.

But, it must be achieved by using raw websockets.


Is This A Good Question/Topic? 0
  • +

Replies To: Basic websocket listener not working

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7243
  • View blog
  • Posts: 24,556
  • Joined: 05-May 12

Re: Basic websocket listener not working

Posted 10 February 2020 - 10:44 AM

Umm. So far what you have above are just vanilla TCP socket. To construct a web socket you need to use the WebSocket.CreateClientWebSocket().

Anyway, the code you have above is trying to connect to If your intent is to listen to that port you need to bind and then listen to that port. See Synchronous Server Socket Example
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1