SignalR - connecting to websocket service from javascript without SignalR library

I have a small SignalR project that I started that now all it does is get a string and return it to all connected users.

I'm wondering, since SignalR is opening websites on my server - how can I connect to the service using normal website javascript code? (I have a reason for doing this without the SignalR library).

I was looking at using Chrome Developer Tools and I found that the address the browser connects to is:

ws://localhost:53675/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=YKgNxA6dhmtHya1srzPPIv6KFIYEjLTFOogXqcjPErFcKCmRdjvS2X6A2KmraW%2BrLnRUNf68gYPdOkOOgJ8yRcq4iCDm%2BbUyLejsr2NySNZBvLloWuMIAvgI6oC%2Fyt%2Ba&connectionData=%5B%7B%22name%22%3A%22ophirhubtest%22%7D%5D&tid=7

      

How do I generate a token?

Then it seems that the messages going between the client and the server are plain json text (which can be easily imitated):

{"C":"d-9E7D682A-A,1|E,0|F,1|G,0","S":1,"M":[]}
{"H":"ophirhubtest","M":"Echo","A":["test"],"I":0}
{"C":"d-9E7D682A-A,2|E,0|F,1|G,0","M":[{"H":"ophirHubTest","M":"printEcho","A":["You said: test"]}]}

      

If I just try to connect than connect, but the connection closes quickly. If I remove the token, it closes immediately.

Can I manually connect to WS?

+3


source to share


1 answer


Before you can connect to the server, a connection occurs. This is when the server sends all the data it needs to send and receive messages. Without negotiating a connection, you will not be able to connect to the server. After you implement connection negotiation, you will probably be implementing the SignalR client twice. I wrote a message



+4


source







All Articles