1

I'm very new to the websocket, I'm trying to make a simple websocket server with c# from scratch, anyone have a simple sample?? that I can understand easily? Like just send string ("hello client") to the client side(HTML5 with JavaScript) I'm using google chrome, Thank you

Eldon Lesley
  • 915
  • 6
  • 19
  • 38
  • If you're building it from scratch for fun, then please pay no attention to me when I say that Websockets are a built-in feature of ASP.net 4.5. See here http://www.paulbatum.com/2011/09/getting-started-with-websockets-in.html – jessegavin Mar 15 '12 at 16:18
  • Is this different from [your question yesterday](http://stackoverflow.com/questions/9704633/receive-data-from-websocket-server-written-in-c-vb-net-as-image)? – simonc Mar 15 '12 at 16:20
  • The question was to use websocket for file transfer, apparently it's really complicated, so I try to ask for a basic one – Eldon Lesley Mar 16 '12 at 07:36
  • Here is to make it clear, I would like to create a server with a basic functionality to send message/string to the client (in browser) – Eldon Lesley Mar 16 '12 at 07:57

3 Answers3

4

I would recommend you Fleck - very easy to start with and clean.

weismat
  • 7,195
  • 3
  • 43
  • 58
  • There is a console app project which shows you the implementation of a chat echo server. Very simple to use. You need to implement delegates for OnOpen, OnClose, OnMessage and can use Send to send data. – weismat Mar 16 '12 at 10:09
  • thanks! it worked! but I need to study the server first, since I need to modify it to send message to the client in string format (customizable) – Eldon Lesley Mar 16 '12 at 10:47
  • unfortunately though, I can't make a server from scratch, and this Fleck is a hell lot of complex code, and need some time to understand, but the usage is very simple – Eldon Lesley Mar 16 '12 at 11:30
  • There is a byte array and a string method - so you should be flexibale in your format - adding another send method should be really trivial. – weismat Mar 16 '12 at 11:43
0

You may also take a look at the WebSocketRPC library, which is simple enough. Some code snippets are shown on the page.

Disclaimer: I am the author.

dajuric
  • 2,373
  • 2
  • 20
  • 43
0
  1. Install .NET Framework 4.5

  2. using System.Net.WebSockets;

dtb
  • 213,145
  • 36
  • 401
  • 431