Skip to content

Commit 7d80e0e

Browse files
committed
docs: xamarin note
[skip ci]
1 parent ce03dff commit 7d80e0e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ An elegant socket.io client for .NET, Supports `.NET Standard 2.0`, support sock
1414
- [JsonSerializer](#jsonserializer)
1515
- [ClientWebSocket Options](#clientwebsocket-options)
1616
- [Windows 7 Support](#windows-7-support)
17+
- [Xamarin](#xamarin)
1718
- [Breaking changes](#breaking-changes)
1819
- [Breaking changes in 3.0.0](#breaking-changes-in-300)
1920
- [Breaking changes in 2.2.4](#breaking-changes-in-224)
@@ -260,6 +261,43 @@ The library uses System.Net.WebSockets.ClientWebSocket by default. Unfortunately
260261
client.ClientWebSocketProvider = () => new ClientWebSocketManaged();
261262
```
262263

264+
## Xamarin
265+
266+
Optimized the support for Xamarin: the library will always try to connect to the server, and an exception will be thrown when the connection fails. The library catches some exception types, such as: TimeoutException, WebSocketException, HttpRequestException and OperationCanceledException. If it is one of then, the library will continue to try to connect to the server. If there are other exceptions, the library will stop reconnecting and throw this exception to the upper layer. You need extra attention in Xamarin.
267+
268+
For Xamarin.Android you should add the following code:
269+
270+
```cs
271+
public partial class MainPage: ContentPage
272+
{
273+
public MainPage()
274+
{
275+
InitializeComponent();
276+
}
277+
278+
public SocketIO Socket {get;}
279+
}
280+
281+
...
282+
283+
public class MainActivity: global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
284+
{
285+
protected override void OnCreate(Bundle savedInstanceState)
286+
{
287+
...
288+
var app = new App();
289+
var mainPage = app.MainPage as MainPage;
290+
mainPage.AddExpectedException(typeof(Java.Net.SocketException));
291+
mainPage.AddExpectedException(typeof(Java.Net.SocketTimeoutException));
292+
LoadApplication(app);
293+
}
294+
295+
...
296+
}
297+
```
298+
299+
I don't have a macOS device, and I don't know the specific exceptions of Xamarin.iOS. Welcome to create a pr and update this document. thanks :)
300+
263301
# Breaking changes
264302

265303
## Breaking changes in 3.0.0

0 commit comments

Comments
 (0)