Changed IsConnected to IsKeepAlive in WebSocket.cs
This commit is contained in:
parent
3ef6d58f31
commit
85ef38084d
Binary file not shown.
@ -49,7 +49,7 @@ namespace Example
|
||||
|
||||
WaitCallback notifyMsg = state =>
|
||||
{
|
||||
while (ts.Enabled)
|
||||
while (ts.Enabled || _msgQ.Count > 0)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
@ -73,9 +73,9 @@ namespace Example
|
||||
|
||||
ThreadPool.QueueUserWorkItem(notifyMsg);
|
||||
|
||||
using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo"))
|
||||
//using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo"))
|
||||
//using (WebSocket ws = new WebSocket("wss://echo.websocket.org", "echo"))
|
||||
//using (WebSocket ws = new WebSocket("ws://localhost:4649"))
|
||||
using (WebSocket ws = new WebSocket("ws://localhost:4649"))
|
||||
{
|
||||
ws.OnOpen += (sender, e) =>
|
||||
{
|
||||
@ -116,7 +116,7 @@ namespace Example
|
||||
Console.Write("> ");
|
||||
data = Console.ReadLine();
|
||||
if (data == "exit")
|
||||
//if (data == "exit" || !ws.IsConnected)
|
||||
//if (data == "exit" || !ws.IsKeepAlive)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -124,7 +124,7 @@ namespace Example1
|
||||
_notifyMsgState = new ThreadState();
|
||||
_notifyMsg = (state) =>
|
||||
{
|
||||
while (_notifyMsgState.Enabled)
|
||||
while (_notifyMsgState.Enabled || _msgQ.Count > 0)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
|
||||
@ -197,7 +197,7 @@ namespace Example1
|
||||
float[,] buffer_array = new float[ch_num, buffer_length];
|
||||
|
||||
int offset = 9;
|
||||
ch_num.Times(i =>
|
||||
((int)ch_num).Times(i =>
|
||||
{
|
||||
buffer_length.Times(j =>
|
||||
{
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -10,5 +10,10 @@ namespace Example2
|
||||
{
|
||||
Send(e.Data);
|
||||
}
|
||||
|
||||
protected override void onClose(object sender, CloseEventArgs e)
|
||||
{
|
||||
Console.WriteLine("[Echo] Close({0}: {1})", (ushort)e.Code, e.Code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -9,7 +9,7 @@ namespace Example2
|
||||
{
|
||||
//var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
|
||||
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649");
|
||||
var wssv = new WebSocketServer<Echo>("/", 4649);
|
||||
var wssv = new WebSocketServer<Echo>(4649);
|
||||
|
||||
wssv.Start();
|
||||
Console.WriteLine(
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -149,48 +149,36 @@ namespace WebSocketSharp
|
||||
return subArray;
|
||||
}
|
||||
|
||||
public static void Times<T>(this T n, Action act)
|
||||
where T : struct
|
||||
public static void Times(this int n, Action act)
|
||||
{
|
||||
if (typeof(T) != typeof(byte) &&
|
||||
typeof(T) != typeof(Int16) &&
|
||||
typeof(T) != typeof(Int32) &&
|
||||
typeof(T) != typeof(Int64) &&
|
||||
typeof(T) != typeof(UInt16) &&
|
||||
typeof(T) != typeof(UInt32) &&
|
||||
typeof(T) != typeof(UInt64))
|
||||
{
|
||||
throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString());
|
||||
}
|
||||
|
||||
ulong m = (ulong)(object)n;
|
||||
|
||||
for (ulong i = 0; i < m; i++)
|
||||
{
|
||||
act();
|
||||
}
|
||||
((ulong)n).Times(act);
|
||||
}
|
||||
|
||||
public static void Times<T>(this T n, Action<ulong> act)
|
||||
where T : struct
|
||||
public static void Times(this uint n, Action act)
|
||||
{
|
||||
if (typeof(T) != typeof(byte) &&
|
||||
typeof(T) != typeof(Int16) &&
|
||||
typeof(T) != typeof(Int32) &&
|
||||
typeof(T) != typeof(Int64) &&
|
||||
typeof(T) != typeof(UInt16) &&
|
||||
typeof(T) != typeof(UInt32) &&
|
||||
typeof(T) != typeof(UInt64))
|
||||
{
|
||||
throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString());
|
||||
}
|
||||
((ulong)n).Times(act);
|
||||
}
|
||||
|
||||
ulong m = (ulong)(object)n;
|
||||
public static void Times(this ulong n, Action act)
|
||||
{
|
||||
for (ulong i = 0; i < n; i++)
|
||||
act();
|
||||
}
|
||||
|
||||
for (ulong i = 0; i < m; i++)
|
||||
{
|
||||
public static void Times(this int n, Action<ulong> act)
|
||||
{
|
||||
((ulong)n).Times(act);
|
||||
}
|
||||
|
||||
public static void Times(this uint n, Action<ulong> act)
|
||||
{
|
||||
((ulong)n).Times(act);
|
||||
}
|
||||
|
||||
public static void Times(this ulong n, Action<ulong> act)
|
||||
{
|
||||
for (ulong i = 0; i < n; i++)
|
||||
act(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static T To<T>(this byte[] src, ByteOrder srcOrder)
|
||||
|
@ -51,7 +51,7 @@ namespace WebSocketSharp.Server {
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
#region Constructors
|
||||
|
||||
public WebSocketServer(string url)
|
||||
{
|
||||
@ -83,6 +83,11 @@ namespace WebSocketSharp.Server {
|
||||
_services = new Dictionary<string, WebSocketService>();
|
||||
}
|
||||
|
||||
public WebSocketServer(int port)
|
||||
: this("/", port)
|
||||
{
|
||||
}
|
||||
|
||||
public WebSocketServer(string absPath, int port)
|
||||
{
|
||||
_uri = new Uri(absPath, UriKind.Relative);
|
||||
@ -177,7 +182,7 @@ namespace WebSocketSharp.Server {
|
||||
|
||||
private void startService(TcpClient client)
|
||||
{
|
||||
WaitCallback startCb = (state) =>
|
||||
WaitCallback startSv = (state) =>
|
||||
{
|
||||
try {
|
||||
var socket = new WebSocket(_uri, client);
|
||||
@ -188,7 +193,7 @@ namespace WebSocketSharp.Server {
|
||||
error(ex.Message);
|
||||
}
|
||||
};
|
||||
ThreadPool.QueueUserWorkItem(startCb);
|
||||
ThreadPool.QueueUserWorkItem(startSv);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -69,6 +69,7 @@ namespace WebSocketSharp
|
||||
private Object _forSend;
|
||||
private int _fragmentLen;
|
||||
private bool _isClient;
|
||||
private bool _isSecure;
|
||||
private Thread _msgThread;
|
||||
private NetworkStream _netStream;
|
||||
private string _protocol;
|
||||
@ -109,6 +110,7 @@ namespace WebSocketSharp
|
||||
_tcpClient = tcpClient;
|
||||
_endPoint = (IPEndPoint)_tcpClient.Client.LocalEndPoint;
|
||||
_isClient = false;
|
||||
_isSecure = _endPoint.Port == 443 ? true : false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -119,7 +121,6 @@ namespace WebSocketSharp
|
||||
: this()
|
||||
{
|
||||
_uri = new Uri(url);
|
||||
|
||||
if (!isValidScheme(_uri))
|
||||
{
|
||||
var msg = "Unsupported WebSocket URI scheme: " + _uri.Scheme;
|
||||
@ -128,6 +129,7 @@ namespace WebSocketSharp
|
||||
|
||||
_protocols = protocols.ToString(", ");
|
||||
_isClient = true;
|
||||
_isSecure = _uri.Scheme == "wss" ? true : false;
|
||||
}
|
||||
|
||||
public WebSocket(
|
||||
@ -179,7 +181,7 @@ namespace WebSocketSharp
|
||||
get { return _extensions; }
|
||||
}
|
||||
|
||||
public bool IsConnected {
|
||||
public bool IsKeepAlive {
|
||||
get {
|
||||
if (_readyState != WsState.OPEN)
|
||||
return false;
|
||||
@ -190,10 +192,7 @@ namespace WebSocketSharp
|
||||
|
||||
public bool IsSecure {
|
||||
get {
|
||||
if (_endPoint.Port == 443)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return _isSecure;
|
||||
}
|
||||
}
|
||||
|
||||
@ -360,21 +359,19 @@ namespace WebSocketSharp
|
||||
|
||||
private void createClientStream()
|
||||
{
|
||||
string scheme = _uri.Scheme;
|
||||
string host = _uri.DnsSafeHost;
|
||||
int port = _uri.Port;
|
||||
|
||||
var host = _uri.DnsSafeHost;
|
||||
var port = _uri.Port;
|
||||
if (port <= 0)
|
||||
{
|
||||
port = 80;
|
||||
if (scheme == "wss")
|
||||
if (IsSecure)
|
||||
port = 443;
|
||||
}
|
||||
|
||||
_tcpClient = new TcpClient(host, port);
|
||||
_netStream = _tcpClient.GetStream();
|
||||
|
||||
if (scheme == "wss")
|
||||
if (IsSecure)
|
||||
{
|
||||
RemoteCertificateValidationCallback validation = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user