Code Monkey home page Code Monkey logo

supersocket.clientengine's Introduction

SuperSocket.ClientEngine Build Status NuGet Version

SuperSocket.ClientEngine is a .NET library for socket client rapid development. It provides easy to use and efficient APIs to simplify your socket development work about asynchronous connecting, data sending, data receiving, network protocol analysising and transfer layer encryption.

Build from Source Code

1. Download source code from Github or clone the repository;
2. Restore dependencies using NuGet; (Latest NuGet Visual Studio extension will restore dependencies before build automatically. You also can follow [This NuGet doc](https://docs.nuget.org/consume/package-restore#package-restore-approaches) to do it manually.)
3. Choose a correct solution file to build;

Install from NuGet

PM> Install-Package SuperSocket.ClientEngine

Usage

Create your ReceiveFilter Implementation according Your Network Protocol

SuperSocket.ClientEngine provides some powerfull basic ReceiveFilter classes (under the namespace "SuperSocket.ProtoBase") to help you simplify your protocol analysis:

TerminatorReceiveFilter
BeginEndMarkReceiveFilter
FixedHeaderReceiveFilter
FixedSizeReceiveFilter
CountSpliterReceiveFilter

You should design your own ReceiveFilter according yoru protocol details base on the basic ReceiveFilters provided by SuperSocket.ClientEngine:

class MyReceiveFilter : TerminatorReceiveFilter<StringPackageInfo>
{
	public MyReceiveFilter()
	: base(Encoding.ASCII.GetBytes("||")) // two vertical bars as package terminator
	{
	}
	
	// other code you need implement according yoru protocol details
}

Create an Instance of EasyClient and Initialize it with the ReceiveFilter which is created in the previous step

var client = new EasyClient();

// Initialize the client with the receive filter and request handler
client.Initialize(new MyReceiveFilter(), (request) => {
	// handle the received request
	Console.WriteLine(request.Key);
});

Make a Connection and then Start the Communication

// Connect to the server
var connected = await client.ConnectAsync(new IPEndPoint(IPAddress.Parse("192.168.10.11"), 25));

if (connected)
{
	// Send data to the server
	client.Send(Encoding.ASCII.GetBytes("LOGIN kerry"));
}

supersocket.clientengine's People

Contributors

berdon avatar bigbearzhu avatar bigsupersniper avatar chucklu avatar gorniv avatar iseebi avatar jturpen avatar kenjiuno avatar kerryjiang avatar leszekm1 avatar mattleibow avatar mbett7 avatar moljac avatar schappel avatar vossjannik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

supersocket.clientengine's Issues

Android app crashes when trying to call Socket.SetSocketOption

Complete stacktrace is below:

[ArgumentException: Value does not fall within the expected range.]
    System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Boolean optionValue) in <filename unknown>:0
    SuperSocket.ClientEngine.TcpClientSession.ProcessConnect(System.Net.Sockets.Socket socket, System.Object state, System.Net.Sockets.SocketAsyncEventArgs e) in <filename unknown>:0
    SuperSocket.ClientEngine.ConnectAsyncExtension.SocketConnectCompleted(System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.ConnectCallback(IAsyncResult ares) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.DispatcherCB(IAsyncResult ares) in <filename unknown>:0

Does it make sense to call that line https://github.com/kerryjiang/SuperSocket.ClientEngine/blob/master/Core/TcpClientSession.cs#L176 in try-catch block?

Socks5 proxy

Hello,

I don't think this is an issue but, is it possible to use SOCKS5 proxies with WebSocket4Net?
All I can find is HttpConnectionProxy but it doesn't handle socks5.

Thanks for the answer ^^

Websocket error.. connects in 3rd attempt

We are using websocket4net (v 0.14.1) in our application. This issue of websocket error unexpectedly is happening on Windows 7 machine only and not with windows 8 or 10.

On windows 7 machine we get following websocket exception..

Web socket error: System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted^M
--- End of inner exception stack trace ---^M
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)^M
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)^M
at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)^M
at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated(IAsyncResult result)^M

i have seen the wireshark traces but nothing has helped yet. Wireshark traces are attached with server ip address = 123.255.13.242 and client IP address = 10.221.12.50 and clients tries websocket connection at port 36008. Our application tries for a websocket connection to the server and get this exception always in first 2 attempt, then the websocket connection is established in 3rd attempt

The websocket connection connects to server port 36008 using TLS v1.2 for the connection with the server.

Win7Fail.zip

how to use the function of 'easyClient' in SuperSocket.ClientEngine ?

I used the class of EasyClient,but the function of 'Initialize' can't be used .
because i don't know the interface of 'IReceiveFilter'.

code:
public void Initialize(IReceiveFilter receiveFilter, Action handler) where TPackageInfo : IPackageInfo
receiveFilter is a instance? Do I have to write it by myself?
could you help me,thanks.

.Net 4.0 无法编译

在.Net 4.0版本加入包后client.ConnectAsync编译不通过,报告 预定义类型“System.Runtime.CompilerServices.AsyncTaskMethodBuilder”未定义或未载入,将工程改为.Net 4.5 后问题消失,作者能否提供一下 .Net 4.0下的使用说明或者DEMO?

从 0.7.0.1 升级至 0.8.0.2,在Xamarin for Android中报“AddressFamily“错误

江老师 您好,

我们项目刚升级到最新的 0.8.0.2,就报这个错误,请问升级后要做什么更改吗? 谢谢!

Unhandled Exception:

System.ArgumentException: The IPEndPoint was created using InterNetwork AddressFamily but SocketAddress contains InterNetworkV6 instead, please use the same type.

In mgmain JNI_OnLoad
08-06 15:37:55.272 E/mono (28585):
08-06 15:37:55.272 E/mono (28585): Unhandled Exception:
08-06 15:37:55.272 E/mono (28585): System.ArgumentException: The IPEndPoint was created using InterNetwork AddressFamily but SocketAddress contains InterNetworkV6 instead, please use the same type.
08-06 15:37:55.272 E/mono (28585): at System.Net.IPEndPoint.Create (System.Net.SocketAddress socketAddress) [0x00022] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/IPEndPoint.cs:95
08-06 15:37:55.272 E/mono (28585): at System.Net.Sockets.Socket.get_LocalEndPoint () [0x00034] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:534
08-06 15:37:55.272 E/mono (28585): at SuperSocket.ClientEngine.TcpClientSession.ProcessConnect (System.Net.Sockets.Socket socket, System.Object state, System.Net.Sockets.SocketAsyncEventArgs e) [0x000a2] in :0
08-06 15:37:55.272 E/mono (28585): at SuperSocket.ClientEngine.ConnectAsyncExtension.SocketAsyncEventCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00037] in :0
08-06 15:37:55.272 E/mono (28585): at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs:221
08-06 15:37:55.272 E/mono (28585): at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs:211
08-06 15:37:55.272 E/mono (28585): at System.Net.Sockets.Socket.m__3 (IAsyncResult ares) [0x00062] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1372
08-06 15:37:55.272 E/mono (28585): at System.Net.Sockets.SocketAsyncResult+c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:150
08-06 15:37:55.272 E/mono (28585): at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00019] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:1280
08-06 15:37:55.272 E/mono (28585): at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:857
08-06 15:37:55.272 E/mono (28585): at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:1212

Stack Trace of client being closed while authenticating. Not sure how to read this.

Below is the stack trace from the error exception thrown in debugging mode on an iOS app in Xamarin Studio. I am trying to connect with wss. I have no idea what this stack trace is telling me so please let me know what this means and what I am doing wrong, if possible.

Mono.Security.Interface.TlsException: Unknown Secure Transport error `RecordOverflow'.
at Security.Tls.AppleTlsContext.CheckStatusAndThrow (Security.SslStatus status, Security.SslStatus[] acceptable) [0x000b1] in /Users/builder/data/lanes/3985/ba11e481/source/xamarin-macios/src/Security/Tls/AppleTlsContext.cs:127

at Security.Tls.AppleTlsContext.ProcessHandshake () [0x00029] in /Users/builder/data/lanes/3985/ba11e481/source/xamarin-macios/src/Security/Tls/AppleTlsContext.cs:205

at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x00033] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:594

at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (Mono.Net.Security.AsyncOperationStatus status) [0x00086] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:272

at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation () [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:218

at Mono.Net.Security.AsyncProtocolRequest.StartOperation () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:199

--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143

at Mono.Net.Security.MobileAuthenticatedStream.EndProcessAuthentication (System.IAsyncResult result) [0x00063] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:245

at Mono.Net.Security.MobileAuthenticatedStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:144

at System.Net.Security.SslStream.EndAuthenticateAsClient (System.IAsyncResult asyncResult) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System/System.Net.Security/SslStream.cs:163

at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated (System.IAsyncResult result) [0x0003a] in :0

EasyClient not working with SSL

Hi,
The HostName in TcpClientSession is not set from EasyClientBase(was earlier set in constructor).

The function OnGetSocket(SocketAsyncEventArgs) in SslStreamTcpSession fails because the HostName is not set. ( sslStream.BeginAuthenticateAsClient(HostName, securityOption.Certificates, securityOption.EnabledSslProtocols, false, OnAuthenticated, sslStream); )

Atle

EasyClient Proxy Sample?

I try the EasyClient.Proxy property and return some problem.I want the test class or sample of EasyClient.Proxy.Thank you!

SuperSocket.ClientEngine is throwing SocketException in unsafe thread from the pool

I committed a fix for this particular case, fee free to discard it and fix it in a better way.

This error, obviously, bring any application to crash immediately.

See below the full stacktrace:
UnhandledException System.Net.Sockets.SocketException (0x80004005): The system detected an invalid pointer address in attempting to use a pointer argument in a call
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at SuperSocket.ClientEngine.ConnectAsyncExtension.OnGetHostAddresses(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Dns.ResolveCallback(Object context)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

现在已经正在使用此 SocketAsyncEventArgs 实例进行异步套接字操作

SuperSocket.ClientEngine version="0.8.0.10" targetFramework="net45" ,部署在IIS上,断线重连的时候都会报这个错。

Exception: System.InvalidOperationException

Message: "现在已经正在使用此 SocketAsyncEventArgs 实例进行异步套接字操作。

StackTrace: 在 System.Net.Sockets.SocketAsyncEventArgs.StartConfiguring()
在 System.Net.Sockets.SocketAsyncEventArgs.SetBufferInternal(Byte[] buffer, Int32 offset, Int32 count)
在 SuperSocket.ClientEngine.AsyncTcpSession.SetBuffer(ArraySegment1 bufferSegment) 在 SuperSocket.ClientEngine.ClientSession.SuperSocket.ClientEngine.IBufferSetter.SetBuffer(ArraySegment1 bufferSegment)
在 SuperSocket.ClientEngine.EasyClientBase.OnSessionDataReceived(Object sender, DataEventArgs e)
在 SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
在 System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
在 System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
异常信息: System.InvalidOperationException
在 System.Net.Sockets.SocketAsyncEventArgs.StartConfiguring()
在 System.Net.Sockets.SocketAsyncEventArgs.SetBufferInternal(Byte[], Int32, Int32)
在 SuperSocket.ClientEngine.AsyncTcpSession.SetBuffer(System.ArraySegment1<Byte>) 在 SuperSocket.ClientEngine.ClientSession.SuperSocket.ClientEngine.IBufferSetter.SetBuffer(System.ArraySegment1)
在 SuperSocket.ClientEngine.EasyClientBase.OnSessionDataReceived(System.Object, SuperSocket.ClientEngine.DataEventArgs)
在 SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(System.Net.Sockets.SocketAsyncEventArgs)
在 System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs)
在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
在 System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError, Int32, System.Net.Sockets.SocketFlags)
在 System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)

System.InvalidOperationException was thrown when sending data with EasyClient

I was using the easy client to send some data.
The source data was pushed into the application from about 20 incoming TCP connections, processed by a AppServer of SocketEngine, which called an EasyClient to send data to another place.
The client was under a pretty low workload, sending about 2 packages a second only. However, it occasionally threw a "System.InvalidOperationException" and the application became unusable afterward.

The following was the stack trace related to the exception. I could not found a line relative to my own code, I deduced that it was in another thread, spawned from the EasyClient.

System.InvalidOperationException: "An asynchronous socket operation is already in progress using this SocketAsyncEventArgs instance.";
SuperSocket.ClientEngine.AsyncTcpSession.SetBuffer(ArraySegment`1 bufferSegment) @ SuperSocket.ClientEngine\Core\AsyncTcpSession.cs[36:13]
SuperSocket.ClientEngine.ClientSession.SuperSocket.ClientEngine.IBufferSetter.SetBuffer(ArraySegment`1 bufferSegment) @ SuperSocket.ClientEngine\Core\ClientSession.cs[207:13]
SuperSocket.ClientEngine.EasyClientBase.OnSessionDataReceived(Object sender, DataEventArgs e) @ SuperSocket.ClientEngine\EasyClientBase.cs[236:13]
SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e) @ SuperSocket.ClientEngine\Core\AsyncTcpSession.cs[89:13]

超过包设定大小,断开连接未清除缓存

if (m_MaxPackageLength > 0)

            {
                var length = receiveCache.Total;

                if (length > m_MaxPackageLength)
                {
                   **m_ReceiveCache.Clear();**
                    return ProcessResult.Create(ProcessState.Error, string.Format("Max package length: {0}, current processed length: {1}", m_MaxPackageLength, length));
                }
            }

Receive Filter

Having a bit of difficulty working out how to use this receive filter.

I am pretty much following the basic set up from the Readme.md for 'MyReceiveFilter'.

I can connect to my TCP server, I can send a command to my TCP server, I fired up Putty in 'raw' mode, connected to my TCP server and sent a message using it:

emit { message: "test" }

My putty session correctly shows 'test||' so I know that my server is working fine, if I debug the MyReceiveFilter.ResolvePackage I can see that 'bufferStream' contains the message, however I am unsure of how to convert the bufferStream to StringPackageInfo.

Usage EasyClient

Command the approach used by GPS Socket Server Sample want to use Easy Client. Thank you

关于datafilter问题

如附件代码

Program.txt
连接到服务端后,

  1. 从服务端发送固定长度字节 FF 00 04 48 00 00,工作正常
  2. 从服务端发送FF 00 04 48 00 00 FF 00 04 48 00 00, 客户端一直收到数据(死循环),不会停止接收
  3. 从服务端发送FF 00 04 48 00 00 FF 00 04 48 00 00 FF 00 04 48 00 00,客户端出错,异常

m_ConnectTaskSource空引用

EasyClientBase在关闭时,或开启多个异步连接时,会提示”m_ConnectTaskSource空引用“
最后只能将EasyClientBase里的两句//m_ConnectTaskSource = null;注释掉,托管平台应该可以自动回收吧。
背景:
自己写继承类SuperSocketClient:EasyClient时,想客户端自动重连服务器,不管什么情况下断开,添加新方法:
public Task Connect(IPEndPoint ipEndPoint)
{
if (!IsConnected)
{
ServerAddress = ipEndPoint;
Task result = ConnectAsync(ipEndPoint);
if (!result.Result)
{
Reconnect();
}
return result;
}
return null;
}

private void Reconnect()
{
if (this.AutoReconnect == TimeSpan.Zero)
{
return;
}

        Action<bool> action = (connected) =>
        {
            if (connected == false)
            {
                Thread.Sleep((int)this.AutoReconnect.TotalMilliseconds);
                Reconnect();
            }
        };

        ConnectAsync(ServerAddress).ContinueWith((t) => action(t.Result));
    }

SuperSocket.ProtoBase v1.7.0.14, Func<> and Action<> errors.

After I updated my project to the latest SuperSocket.ProtoBase v1.7.0.14 through NuGet, I'm beginning to get

The type 'Func' exists in both 'SuperSocket.ProtoBase' and 'mscorlib'

I'm using both System.Func<> and System.Action<> and they are now throwing errors because SuperSocket.ProtoBase now apparently has also the same type with the same namespace.

Building with netstandard

When building project targeted netstandard1.6 (or 1.3) with reference "WebSocket4Net": "0.15.0-beta6" getting error:
The type 'ConcurrentQueue<T>' exists in both 'SuperSocket.ClientEngine, Version=0.8.0.6, Culture=neutral, PublicKeyToken=null' and 'System.Collections.Concurrent, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
You can add line
"../Core/ConcurrentQueue.cs"
to excludeFiles section and
"NETStandard.Library": "1.3.0",
to dependencies section.

Nuget Install error on UWP

Trying to install the SuperSocket.ClientEngine on UWP, I get the following NuGet errors:

System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm.
One or more packages are incompatible with UAP,Version=v10.0 (win10-arm).
System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot).
System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64).
System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot).
System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86).
System.Net.Security 4.0.0 provides a compile-time reference assembly for System.Net.Security on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).

Therefore, package restore fails and NuGet automatically unrolls the transaction: The package is not installed. The only place I found where a reason for this was explained is https://github.com/dotnet/corefx/issues/10709 where a direct reference to a class not available on UWP breaks the build. Could this be a reason for this NuGet failure as well?

EasyClient

Are there any events for EasyClient, especially with regards to the server disappearing (for instance the server may have crashed)?

Also, is there a timeout for the easyclient TCP connection to a server, or does it remain open forever until it is closed either by a software crash (server or client) or the client is gracefully closed down? I'm hoping it remains open forever, but if it doesn't, is there a way to keep it open forever without resorting to 'KeepAlive' packets?

35版本以上都编译不过,包括35版本,请问需要做什么处理么!

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 CS0433 类型“Func<T, TResult>”同时存在于“SuperSocket.ProtoBase, Version=1.7.0.14, Culture=neutral, PublicKeyToken=6c80000676988ebb”和“System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中 SuperSocket.ClientEngine.Net35 C:\Users\jinqi\Downloads\SuperSocket.ClientEngine-master\Common\ConcurrentBatchQueue.Net20.cs 19 活动的

好多透视用的都是net20的文件

ValidateRemoteCertificate returns false with "Trusted" self-signed certificates

Conditions:

  • The client is connecting to a Websocket server that uses a self-signed certificate.
  • The client has enabled AllowUntrustedCertificate flag.
  • The client has added the certificate to its Trusted Root Certificates store.

Result:

  • ValidateRemoteCertificate will return false because sslPolicyErrors does not contain RemoteCertificateChainErrors but contains a RemoteCertificateNameMismatch error.
  • If we remove the certificate from the client's Trusted Root Certificate store, ValidateRemoteCertificate will return true (sslPolicyErrors will contain both RemoteCertificateChainErrors and RemoteCertificateNameMismatch).

This is not the typical scenario. However, it does not feel right to throw an invalid certificate error just because the client has decided that the certificate should be trusted (adding it to the Trusted Root Certificate store).

Link to ValidateRemoteCertificate: https://github.com/kerryjiang/SuperSocket.ClientEngine/blob/master/Core/SslStreamTcpSession.cs#L165

cannot connect to server in mono

`2017-01-31 10:15:07,152 [Threadpool worker] ERROR DefaultBootstrap - The process crashed for an unhandled exception!
System.Net.Sockets.SocketException (0x80004005): 提供了一个无效的参数。

at System.Net.Sockets.Socket.GetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName) [0x00023] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.Socket.get_NoDelay () [0x0000c] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at SuperSocket.ClientEngine.ClientSession.OnConnected () [0x00011] in <92d4f34fe64b46bf9231db3b76cda87b>:0
at SuperSocket.ClientEngine.AsyncTcpSession.OnGetSocket (System.Net.Sockets.SocketAsyncEventArgs e) [0x0008d] in <92d4f34fe64b46bf9231db3b76cda87b>:0
at SuperSocket.ClientEngine.TcpClientSession.ProcessConnect (System.Net.Sockets.Socket socket, System.Object state, System.Net.Sockets.SocketAsyncEventArgs e) [0x0017f] in <92d4f34fe64b46bf9231db3b76cda87b>:0
at SuperSocket.ClientEngine.ConnectAsyncExtension.SocketAsyncEventCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00045] in <92d4f34fe64b46bf9231db3b76cda87b>:0
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.Socket.m__3 (System.IAsyncResult ares) [0x00062] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.SocketAsyncResult+c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00019] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
`

how to use commandbase in client?

Dear Jiang,

我们知道在服务器端我们可以使用如下类似的class来识别协议里面的关键字
public class ECHO : StringCommandBase

但是在client端,同样需要识别来自服务端的消息,如何构建commandbase,没有appsession呀!

感谢!

发送内容 服务端无法收到

仿照demo 里的发送 服务端也SuperSocket,建立的。。。

var appServer = new AppServer();
appServer.NewSessionConnected += new SessionHandler<AppSession(appServer_NewSessionConnected); //可以获取
appServer.NewRequestReceived += (session, requestInfo) => Console.WriteLine("new request: Key={0}", requestInfo.Key);//无法获取 哪里没做对么。。 用微软的类写的发送 是可以捕获事件的

Send(ArraySegment) versus Send(byte[])

Hi

I implement server with BinaryReceiveFilter and write this client code:

session.Connect();

while (!session.IsConnected)
   Thread.Sleep(200);

session.Send(buf, 0, buf.Length);

this code work perfect!
but next code:

session.Connect();

while (!session.IsConnected)
   Thread.Sleep(200);

//buf.Length = 116
var seg1 = new ArraySegment<byte>(buf, 0, 80);
var seg2 = new ArraySegment<byte>(buf, 80, buf.Length - 80);

session.Send(seg1);
session.Send(seg2);

this code after call session.Send(seg2); activate my command on server, but in requestInfo.Body It looks so that each segment starts with a header! In my case header equals 5 byte.

It's normal? How to prevent writing header in body?

Thanks.

m_ConnectTaskSource.SetResult时报错

m_ConnectTaskSource.SetResult时报错,提示此任务已经结束了,不能再赋值。
我只能修改了源码:
if (!m_ConnectTaskSource.Task.IsCompleted)
{
m_ConnectTaskSource.SetResult(false/true);
}

Can be Compatible with SuperSocket?

我用SuperSocket 生成了自己的协议,把她放在了一个公共的类库里,想让客户端和服务端共享这部分代码,但client用的时候提示没有 从IRequestInfo 到 IPackageInfo转化的方法。
这是不是意味着我需要把客户端也用和服务端类似的写法用IPackgeInfo那一套东西重写一下。。

AsyncTcpSession关闭连接后,重连出错

使用AsyncTcpSession.Connect方法,连接成功后,主动调用Close()方法,此时session.IsConnected已经为false了,再次调用session.Connect方法,连接不成功,进session.Error了,报这个错System.Net.Sockets.SocketException: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
这是为什么啊?
是不是关闭连接后,必须重新new AsyncTcpSession()才行啊?

SuperSocket.ClientEngine.TcpClientSession.TrySend() throws uncaught exception if socket not connected

Here's the full stack trace (captured from a global exception handler):

01/09/2014 20:53:49.777 [Exception] 01/09/2014 20:53:49.777 ERROR: GlobalUnhandledException The socket is not connected! @ at SuperSocket.ClientEngine.TcpClientSession.TrySend(ArraySegment1 segment) | at SuperSocket.ClientEngine.ClientSession.Send(ArraySegment1 segment)
| at SuperSocket.ClientEngine.ClientSession.Send(Byte[] data, Int32 offset, Int32 length)
| at WebSocket4Net.Protocol.DraftHybi10Processor.SendCloseHandshake(WebSocket websocket, Int32 statusCode, String closeReason)
| at WebSocket4Net.Command.Handshake.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
| at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
| at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
| at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
| at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
| at System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
| at System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)
| at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
| at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
| at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
| at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
| at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
| at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
| at System.Net.ContextAwareResult.Complete(IntPtr userToken)
| at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
| at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

With .Net 4.5, this also causes the whole app to crash (due to a known .Net framework issue with uncaught exceptions) ...

Application: myapp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception
Stack:
at System.Net.FixedSizeReader.ReadCallback(System.IAsyncResult)
at System.Net.LazyAsyncResult.Complete(IntPtr)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.ContextAwareResult.Complete(IntPtr)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped_)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped)

Azure WebApp - SocketException (0x80004005)

Receiving the following error when running inside an Azure WebApp:
System.Net.Sockets.SocketException (0x80004005): An address incompatible with the requested protocol was used
I have a pull request coming to work around this issue.

EasyClient await cannot receive msg from server

//tested EasyClient is running in Windows

//when AppServer is from Windows
await client.ConnectAsync(new DnsEndPoint("185.120.5.51", 2012)); // ok
client.ConnectAsync(new DnsEndPoint("185.120.5.51", 2012)).Wait() // ok

//when AppServer is from Linux
await client.ConnectAsync(new DnsEndPoint("185.120.5.51", 2012)); // client not receive any message from server
client.ConnectAsync(new DnsEndPoint("185.120.5.51", 2012)).Wait() // ok

//accessing AppServer is from Linux using windows telnet client is no problem, windows telnet client can receive message from AppServer

SocketOptionName.KeepAlive on iOS failing intermitently

Hey there,
from time to time, below line fails on iOS devices:

if !SILVERLIGHT

        //Set keep alive
        Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

endif

this is on ProcessConnect of TcpClientSession.cs.

It only happens on release mode, I've not even a single repro with DEBUG on. This is the call stack, as capture by RayGun:

[ArgumentException: Value does not fall within the expected range.]
    System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Boolean optionValue) in <filename unknown>:0
    SuperSocket.ClientEngine.TcpClientSession.ProcessConnect2(System.Object socket, System.Net.Sockets.SocketAsyncEventArgs e) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.ConnectCallback(IAsyncResult ares) in <filename unknown>:0
    System.Net.Sockets.SocketAsyncEventArgs.DispatcherCB(IAsyncResult ares) in <filename unknown>:0
    System.Net.Sockets.Socket+SocketAsyncResult.<DoMConnectCallback>m__0(System.Object _) in <filename unknown>:0

As for OS version, it can happen on any one and on any device, I've 742 entries, and a very spread range of OS version and devices.

I've even found something online talking about this line:
http://fastchicken.co.nz/2014/02/11/making-xamarin-ios-talk-to-meteor/

But looks like for him it was ALWAYS failing.

I've tested without it and my iOS app does NOT work.

Hope it's clear,
CodeKnox

Can't build Droid on VS+Xamarin?

Opening the solution SuperSocket.ClientEngine.MonoDroid.sln and trying to build create this 3 files:

    Common/Properties/AndroidManifest.xml
    Core/Properties/AndroidManifest.xml
    Proxy/Properties/AndroidManifest.xml

and VS build fails with:

1>------ Rebuild All started: Project: Common.MonoDroid, Configuration: Debug Any CPU ------
1> Common.MonoDroid -> C:\fileZ\projZ\Chat.Master\Vendor\SuperSocket.ClientEngine\Common\bin\Debug\SuperSocket.ClientEngine.Common.dll
2>------ Rebuild All started: Project: Core.MonoDroid, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: Proxy.MonoDroid, Configuration: Debug Any CPU ------
2> Core.MonoDroid -> C:\fileZ\projZ\Chat.Master\Vendor\SuperSocket.ClientEngine\Core\bin\Debug\SuperSocket.ClientEngine.Core.dll
2>C:\fileZ\projZ\Chat.Master\Vendor\SuperSocket.ClientEngine\Core\obj\Debug\android\AndroidManifest.xml(5): error : No resource found that matches the given name (at 'icon' with value '@drawable/icon').
4>------ Rebuild All started: Project: Protocol.MonoDroid, Configuration: Debug Any CPU ------
3> Proxy.MonoDroid -> C:\fileZ\projZ\Chat.Master\Vendor\SuperSocket.ClientEngine\Proxy\bin\Debug\SuperSocket.ClientEngine.Proxy.dll
3>C:\fileZ\projZ\Chat.Master\Vendor\SuperSocket.ClientEngine\Proxy\obj\Debug\android\AndroidManifest.xml(5): error : No resource found that matches the given name (at 'icon' with value '@drawable/icon').
========== Rebuild All: 1 succeeded, 3 failed, 0 skipped ==========

Looks liek we are missing an icon and some manifest files??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.