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 =>
|
WaitCallback notifyMsg = state =>
|
||||||
{
|
{
|
||||||
while (ts.Enabled)
|
while (ts.Enabled || _msgQ.Count > 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ namespace Example
|
|||||||
|
|
||||||
ThreadPool.QueueUserWorkItem(notifyMsg);
|
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("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) =>
|
ws.OnOpen += (sender, e) =>
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ namespace Example
|
|||||||
Console.Write("> ");
|
Console.Write("> ");
|
||||||
data = Console.ReadLine();
|
data = Console.ReadLine();
|
||||||
if (data == "exit")
|
if (data == "exit")
|
||||||
//if (data == "exit" || !ws.IsConnected)
|
//if (data == "exit" || !ws.IsKeepAlive)
|
||||||
{
|
{
|
||||||
break;
|
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();
|
_notifyMsgState = new ThreadState();
|
||||||
_notifyMsg = (state) =>
|
_notifyMsg = (state) =>
|
||||||
{
|
{
|
||||||
while (_notifyMsgState.Enabled)
|
while (_notifyMsgState.Enabled || _msgQ.Count > 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ namespace Example1
|
|||||||
float[,] buffer_array = new float[ch_num, buffer_length];
|
float[,] buffer_array = new float[ch_num, buffer_length];
|
||||||
|
|
||||||
int offset = 9;
|
int offset = 9;
|
||||||
ch_num.Times(i =>
|
((int)ch_num).Times(i =>
|
||||||
{
|
{
|
||||||
buffer_length.Times(j =>
|
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);
|
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<Echo>("ws://localhost:4649");
|
||||||
//var wssv = new WebSocketServer<Chat>("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();
|
wssv.Start();
|
||||||
Console.WriteLine(
|
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;
|
return subArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Times<T>(this T n, Action act)
|
public static void Times(this int n, Action act)
|
||||||
where T : struct
|
|
||||||
{
|
{
|
||||||
if (typeof(T) != typeof(byte) &&
|
((ulong)n).Times(act);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Times<T>(this T n, Action<ulong> act)
|
public static void Times(this uint n, Action act)
|
||||||
where T : struct
|
|
||||||
{
|
{
|
||||||
if (typeof(T) != typeof(byte) &&
|
((ulong)n).Times(act);
|
||||||
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;
|
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);
|
act(i);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T To<T>(this byte[] src, ByteOrder srcOrder)
|
public static T To<T>(this byte[] src, ByteOrder srcOrder)
|
||||||
|
@ -51,7 +51,7 @@ namespace WebSocketSharp.Server {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor
|
#region Constructors
|
||||||
|
|
||||||
public WebSocketServer(string url)
|
public WebSocketServer(string url)
|
||||||
{
|
{
|
||||||
@ -83,6 +83,11 @@ namespace WebSocketSharp.Server {
|
|||||||
_services = new Dictionary<string, WebSocketService>();
|
_services = new Dictionary<string, WebSocketService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebSocketServer(int port)
|
||||||
|
: this("/", port)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public WebSocketServer(string absPath, int port)
|
public WebSocketServer(string absPath, int port)
|
||||||
{
|
{
|
||||||
_uri = new Uri(absPath, UriKind.Relative);
|
_uri = new Uri(absPath, UriKind.Relative);
|
||||||
@ -177,7 +182,7 @@ namespace WebSocketSharp.Server {
|
|||||||
|
|
||||||
private void startService(TcpClient client)
|
private void startService(TcpClient client)
|
||||||
{
|
{
|
||||||
WaitCallback startCb = (state) =>
|
WaitCallback startSv = (state) =>
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
var socket = new WebSocket(_uri, client);
|
var socket = new WebSocket(_uri, client);
|
||||||
@ -188,7 +193,7 @@ namespace WebSocketSharp.Server {
|
|||||||
error(ex.Message);
|
error(ex.Message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ThreadPool.QueueUserWorkItem(startCb);
|
ThreadPool.QueueUserWorkItem(startSv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -69,6 +69,7 @@ namespace WebSocketSharp
|
|||||||
private Object _forSend;
|
private Object _forSend;
|
||||||
private int _fragmentLen;
|
private int _fragmentLen;
|
||||||
private bool _isClient;
|
private bool _isClient;
|
||||||
|
private bool _isSecure;
|
||||||
private Thread _msgThread;
|
private Thread _msgThread;
|
||||||
private NetworkStream _netStream;
|
private NetworkStream _netStream;
|
||||||
private string _protocol;
|
private string _protocol;
|
||||||
@ -109,6 +110,7 @@ namespace WebSocketSharp
|
|||||||
_tcpClient = tcpClient;
|
_tcpClient = tcpClient;
|
||||||
_endPoint = (IPEndPoint)_tcpClient.Client.LocalEndPoint;
|
_endPoint = (IPEndPoint)_tcpClient.Client.LocalEndPoint;
|
||||||
_isClient = false;
|
_isClient = false;
|
||||||
|
_isSecure = _endPoint.Port == 443 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -119,7 +121,6 @@ namespace WebSocketSharp
|
|||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
_uri = new Uri(url);
|
_uri = new Uri(url);
|
||||||
|
|
||||||
if (!isValidScheme(_uri))
|
if (!isValidScheme(_uri))
|
||||||
{
|
{
|
||||||
var msg = "Unsupported WebSocket URI scheme: " + _uri.Scheme;
|
var msg = "Unsupported WebSocket URI scheme: " + _uri.Scheme;
|
||||||
@ -128,6 +129,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
_protocols = protocols.ToString(", ");
|
_protocols = protocols.ToString(", ");
|
||||||
_isClient = true;
|
_isClient = true;
|
||||||
|
_isSecure = _uri.Scheme == "wss" ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocket(
|
public WebSocket(
|
||||||
@ -179,7 +181,7 @@ namespace WebSocketSharp
|
|||||||
get { return _extensions; }
|
get { return _extensions; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsConnected {
|
public bool IsKeepAlive {
|
||||||
get {
|
get {
|
||||||
if (_readyState != WsState.OPEN)
|
if (_readyState != WsState.OPEN)
|
||||||
return false;
|
return false;
|
||||||
@ -190,10 +192,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
public bool IsSecure {
|
public bool IsSecure {
|
||||||
get {
|
get {
|
||||||
if (_endPoint.Port == 443)
|
return _isSecure;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,21 +359,19 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
private void createClientStream()
|
private void createClientStream()
|
||||||
{
|
{
|
||||||
string scheme = _uri.Scheme;
|
var host = _uri.DnsSafeHost;
|
||||||
string host = _uri.DnsSafeHost;
|
var port = _uri.Port;
|
||||||
int port = _uri.Port;
|
|
||||||
|
|
||||||
if (port <= 0)
|
if (port <= 0)
|
||||||
{
|
{
|
||||||
port = 80;
|
port = 80;
|
||||||
if (scheme == "wss")
|
if (IsSecure)
|
||||||
port = 443;
|
port = 443;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tcpClient = new TcpClient(host, port);
|
_tcpClient = new TcpClient(host, port);
|
||||||
_netStream = _tcpClient.GetStream();
|
_netStream = _tcpClient.GetStream();
|
||||||
|
|
||||||
if (scheme == "wss")
|
if (IsSecure)
|
||||||
{
|
{
|
||||||
RemoteCertificateValidationCallback validation = (sender, certificate, chain, sslPolicyErrors) =>
|
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