Bug 19449 - Missing .Net 4.5 API for WebSockets
Summary: Missing .Net 4.5 API for WebSockets
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 1.8.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-05-01 08:03 UTC by Ken
Modified: 2015-01-20 08:36 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Ken 2014-05-01 08:03:52 UTC
Description of Problem:
I saw that the WebSockets API is now available and since one of my projects is to be a service that runs on a Mac, iOS and Android device I decided to give it try.

I started with a new Xamarin.Mac Project solution and modified the main.cs file (you can just replace the contents of main.cs with the code below).

Note: This code is taken from a Visual Studio C# project I wrote several months ago that builds and run okay on Windows 8.1.


using System;
using System.Drawing;
using System.Net;
using System.Net.WebSockets;

using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using System.Net.Sockets;

namespace WebSocketsServerExample
{
	class WebSocketSession
	{
		internal static void Create(WebSocketContext webSocketContext)
		{

		}
	}

	class WebSocketServer
	{
		internal static void StartServerThreads()
		{
		}

		public static async void WebSocketServerListener()
		{
			HttpListener httpListener = new HttpListener ();
//			TcpListener tcpListener = new TcpListener (12000);

			httpListener.Prefixes.Add ("http://+:80/WebSocketExample/");
//			httpListener.Prefixes.Add ("https://+:443/WebSocketExample/");

			httpListener.Start ();

			while (true) {
				HttpListenerContext httpListenerContext = await httpListener.GetContextAsync ();
				if (httpListenerContext.Request.IsWebSocketRequest) {
					ProcessWebSocketConnectionRequest (httpListenerContext);
				} else {
					httpListenerContext.Response.StatusCode = 400;
					httpListenerContext.Response.Close ();
				}
			}
		}

		private static async void ProcessWebSocketConnectionRequest(HttpListenerContext httpListenerContext)
		{
			try {
				WebSocketContext webSocketContext = await httpListenerContext.AcceptWebSocketAsync(subprotocol: "Womp-like");
				WebSocketSession.Create(webSocketContext);
			}
			catch (Exception e) {
				httpListenerContext.Response.StatusCode = 500;
				httpListenerContext.Response.Close ();
				Console.WriteLine ("Exception:{0}", e);
			}
		}
	}

	class MainClass
	{
		static void Main (string[] args)
		{
			NSApplication.Init ();
			NSApplication.Main (args);
		}
	}
}


Actual Results:

Main.cs(51,67): error CS1061: Type `System.Net.HttpListenerContext' does not contain a definition for `AcceptWebSocketAsync' and no extension method `AcceptWebSocketAsync' of type `System.Net.HttpListenerContext' could be found. Are you missing an assembly reference?

Expected Results:

I would have thought this should work since according to Miguel the WebSockets API is available and it is in the stable channel.

How often does this happen? 

All the time....

Additional Information:

Xamarin Studio
Version 5.0 (build 784)
Installation UUID: 23b0fbc7-ece4-4a1e-b1a7-d0b20e74378d
Runtime:
	Mono 3.4.0 ((no/51469e6)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000202

Apple Developer Tools
Xcode 5.1.1 (5085)
Build 5B1008

Xamarin.Mac
Xamarin.Mac: 1.8.0.8

Xamarin.Android
Version: 4.12.4 (Business Edition)
Android SDK: /Developer/Android/sdk
	Supported Android versions:
		4.4 (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Xamarin.iOS
Version: 7.2.3.20 (Business Edition)
Hash: 865c609
Branch: 
Build date: 2014-04-29 00:45:34-0400

Build Information
Release ID: 500000784
Git revision: ea367c9e829e7c627ec8927e8832df6a74390d61
Build date: 2014-04-29 09:48:53-04
Xamarin addins: 92dcfc8532a8c6d21783289c176417d7c17bf492

Operating System
Mac OS X 10.9.2
Darwin MachineName.local 13.1.0 Darwin Kernel Version 13.1.0
    Wed Apr  2 23:52:02 PDT 2014
    root:xnu-2422.92.1~2/RELEASE_X86_64 x86_64
Comment 1 Ram Chandra 2014-05-01 09:52:13 UTC
I have checked this issue and I am able to reproduce this issue.

Steps to reproduce:
1. Open an "iOS Single View Application" on XS.
2. Paste the above code into "main.cs" file (mentioned in bug description).
3. Add the System.Net reference. (right click on References folder -> Edit References..)
4. Build the project.

I observed that when add the above code into the "main.cs" and build the project I am getting following exception :
"/Users/jatin66/Desktop/Test12/Test12/Main.cs(41,41): Error CS1061: Type `System.Net.HttpListenerContext' does not contain a definition for `AcceptWebSocketAsync' and no extension method `AcceptWebSocketAsync' of type `System.Net.HttpListenerContext' could be found. Are you missing an assembly reference? (CS1061) (Test12)".

I have checked the definition of  class"HttpListenerContext" in assembly browser and it doesn't contain the definition of "HttpListenerContext".

I have also try the same with "Xamarin.Mac" project but It doesn't find "System.Net.WebSockets;"  namespace.

Screencast: http://www.screencast.com/t/RblwsyyQ5KV

Application output log: https://gist.github.com/saurabh360/e6b5e6d9dcccc51f32da

Please let me know if I am missing anything.

Environment Info:

Xamarin Studio
Version 5.0 (build 784)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 302060000

Apple Developer Tools
Xcode 5.1 (5084)
Build 5B130a

Xamarin.iOS
Version: 7.2.3.20 (Trial Edition)
Hash: 865c609
Branch: 
Build date: 2014-04-29 00:45:34-0400

Xamarin.Android
Version: 4.12.1 (Trial Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

Xamarin.Mac
Xamarin.Mac: 1.8.0.8

Build Information
Release ID: 500000784
Git revision: ea367c9e829e7c627ec8927e8832df6a74390d61
Build date: 2014-04-29 09:48:53-04
Xamarin addins: 92dcfc8532a8c6d21783289c176417d7c17bf492

Operating System
Mac OS X 10.9.2
Darwin Jatin66s-iMac.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 3 Timothy Risi 2015-01-19 17:58:19 UTC
The AcceptWebSocketAsync method now exists
Comment 4 Ram Chandra 2015-01-20 05:40:55 UTC
I have checked this issue with following builds:

Mac OS X 10.9.5
Xamarin Studio :5.7.1 (build 14)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Mono 3.12.0 ((detached/a813491)
GTK+ 2.24.23 (Raleigh theme)
Package version: 312000068
Xcode 6.1 (6604)
Build 6A1052d
Xamarin.Mac: 1.12.0.4 (Business Edition)
=== Build Information ===
Release ID: 507010014
Git revision: a4dd61ad7f8b3695be4b17bcb5c3ae6b81438cf7
Build date: 2015-01-19 15:21:09-05
Xamarin addins: 081208fe3bbf40e24a562867c6c7fba20a9b94b6

Observations: I have checked this issue and I observed that the "AcceptWebSocketAsync" is exist in "HttpListenerContext" class.

Screencast: http://www.screencast.com/t/dfKmmlEw9Ijm

This issue has been fixed. Hence, I am closing this issue.