Thursday, May 24, 2018

C# server respond to socket.io

Leave a Comment

I currently am working on a new project which will contain of a client in JavaScript with socket.io and a server in C#.

However, I have no clue how to respond to the data sent when I connect my client to the server.

In my JavaScript I have:

var socket = io('http://127.0.0.1:30000'); 

And I have SocketTest open and a server started on port 30000. SocketTest will receive the following data:

GET /socket.io/?EIO=3&transport=polling&t=MDMuIkH HTTP/1.1 Host: 127.0.0.1:30000 Connection: keep-alive Accept: */* Origin: http://127.0.0.1:8080 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36 Referer: http://127.0.0.1:8080/ Accept-Encoding: gzip, deflate, br Accept-Language: nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7 Cookie: SOME COOKIE DATA 

What do I correctly send back to the client with this?

2 Answers

Answers 1

Take a look here: C# Server Socket Program

You have to do networkStream.Read and networkStream.Write and whatever you decide to write back, you just need to interpret correctly on the JavaScript side.

However

I suggest you take a look at JSON and maybe the following site because you are doing things that have been done for you already. Posting URL-encoded key values with HttpClient

Answers 2

The server is connected to the Port 30000, so you need to reads data from NetworkStream , and also write to the NetworkStream .

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment