fix WebSocket.cs, WsStream.cs, wsclient.cs

This commit is contained in:
sta
2010-10-21 01:35:50 +09:00
parent 6cd3f2ad91
commit 6b75c09ed2
26 changed files with 98 additions and 54 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release_Ubuntu" ctype="Workspace" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" ctype="Workspace" />
<MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench"> <MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench">
<Files> <Files>
<File FileName="websocket-sharp/WebSocket.cs" Line="231" Column="1" /> <File FileName="websocket-sharp/WebSocket.cs" Line="100" Column="1" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>
+10 -20
View File
@@ -30,9 +30,6 @@
*/ */
#endregion #endregion
#if NOTIFY
using Notifications;
#endif
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -109,13 +106,7 @@ namespace WebSocketSharp
private SslStream sslStream; private SslStream sslStream;
private IWsStream wsStream; private IWsStream wsStream;
private Thread msgThread; private Thread msgThread;
#if NOTIFY
private Notification msgNf;
public Notification MsgNf
{
get { return msgNf; }
}
#endif
public event EventHandler OnOpen; public event EventHandler OnOpen;
public event MessageEventHandler OnMessage; public event MessageEventHandler OnMessage;
public event MessageEventHandler OnError; public event MessageEventHandler OnError;
@@ -205,11 +196,6 @@ namespace WebSocketSharp
readyState = state; readyState = state;
if (OnClose != null)
{
OnClose(this, EventArgs.Empty);
}
if (wsStream != null && tcpClient.Connected) if (wsStream != null && tcpClient.Connected)
{ {
try try
@@ -240,6 +226,14 @@ namespace WebSocketSharp
tcpClient.Close(); tcpClient.Close();
tcpClient = null; tcpClient = null;
} }
if (OnClose != null)
{
OnClose(this, EventArgs.Empty);
}
#if DEBUG
Console.WriteLine("WS: Info @close: Exit close method.");
#endif
} }
private void createConnection() private void createConnection()
@@ -355,10 +349,6 @@ namespace WebSocketSharp
Console.WriteLine("WS: Info @message: Current thread IsBackground: {0}", Thread.CurrentThread.IsBackground); Console.WriteLine("WS: Info @message: Current thread IsBackground: {0}", Thread.CurrentThread.IsBackground);
#endif #endif
string data; string data;
#if NOTIFY
this.msgNf = new Notification();
msgNf.AddHint("append", "allowed");
#endif
while (readyState == WsState.OPEN) while (readyState == WsState.OPEN)
{ {
data = receive(); data = receive();
@@ -435,7 +425,7 @@ namespace WebSocketSharp
OnError(this, e.Message); OnError(this, e.Message);
} }
ReadyState = WsState.CLOSING; ReadyState = WsState.CLOSED;
#if DEBUG #if DEBUG
Console.WriteLine("WS: Error @receive: {0}", e.Message); Console.WriteLine("WS: Error @receive: {0}", e.Message);
#endif #endif
+7 -7
View File
@@ -42,16 +42,16 @@ namespace WebSocketSharp
public WsStream(T innerStream) public WsStream(T innerStream)
{ {
if (innerStream == null) Type streamType = typeof(T);
{
throw new ArgumentNullException("innerStream");
}
Type streamType = innerStream.GetType();
if (streamType != typeof(NetworkStream) && if (streamType != typeof(NetworkStream) &&
streamType != typeof(SslStream)) streamType != typeof(SslStream))
{ {
throw new ArgumentException("Unsupported Stream type: " + streamType.ToString()); throw new NotSupportedException("Unsupported Stream type: " + streamType.ToString());
}
if (innerStream == null)
{
throw new ArgumentNullException("innerStream");
} }
this.innerStream = innerStream; this.innerStream = innerStream;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -2
View File
@@ -34,7 +34,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug_Ubuntu</OutputPath> <OutputPath>bin\Debug_Ubuntu</OutputPath>
<DefineConstants>DEBUG,NOTIFY</DefineConstants> <DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
@@ -46,7 +46,6 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
<DefineConstants>NOTIFY</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
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.
+9 -21
View File
@@ -1,4 +1,4 @@
#if LINUX #if NOTIFY
using Notifications; using Notifications;
#endif #endif
using System; using System;
@@ -19,36 +19,24 @@ namespace Example
//Do something. //Do something.
}; };
*/ */
ws.OnMessage += (o, e) => ws.OnMessage += (o, s) =>
{ {
#if LINUX #if NOTIFY
#if NOTIFY
ws.MsgNf.Summary = "[WebSocket] Message";
ws.MsgNf.Body = e;
ws.MsgNf.IconName = "notification-message-im";
ws.MsgNf.Show();
#else
Notification nf = new Notification("[WebSocket] Message", Notification nf = new Notification("[WebSocket] Message",
e, s,
"notification-message-im"); "notification-message-im");
nf.AddHint("append", "allowed");
nf.Show(); nf.Show();
#endif
#else #else
Console.WriteLine(e); Console.WriteLine("[WebSocket] Message: {0}", s);
#endif #endif
}; };
ws.OnError += (o, e) => ws.OnError += (o, s) =>
{ {
#if LINUX Console.WriteLine("[WebSocket] Error : {0}", s);
Notification nf = new Notification("[WebSocket] Error",
e,
"notification-network-disconnected");
nf.Show();
#else
Console.WriteLine("Error: {0}", e);
#endif
}; };
/*ws.OnClose += (o, e) => /*ws.OnClose += (o, e) =>
{ {
//Do something. //Do something.
+68 -1
View File
@@ -1 +1,68 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>WsClient</RootNamespace>
<AssemblyName>wsclient</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Ubuntu|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug_Ubuntu</OutputPath>
<DefineConstants>DEBUG,NOTIFY</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Ubuntu|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release_Ubuntu</OutputPath>
<DefineConstants>NOTIFY</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a">
<Package>notify-sharp</Package>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="wsclient.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\websocket-sharp\websocket-sharp.csproj">
<Project>{B357BAC7-529E-4D81-A0D2-71041B19C8DE}</Project>
<Name>websocket-sharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.