Skip to content

Commit 240a4e6

Browse files
committed
fix Ext.cs, WebSocket.cs and Add wsclient1/*
1 parent 7cea727 commit 240a4e6

40 files changed

+212
-8
lines changed

websocket-sharp.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocket-sharp", "websocke
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsclient", "wsclient\wsclient.csproj", "{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsclient1", "wsclient1\wsclient1.csproj", "{B0B609B7-A81C-46B0-A9B8-82E9716D355B}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,14 @@ Global
2123
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
2224
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
27+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
28+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
31+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
32+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{B0B609B7-A81C-46B0-A9B8-82E9716D355B}.Release|Any CPU.Build.0 = Release|Any CPU
2434
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
2535
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
2636
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

websocket-sharp.userprefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" ctype="Workspace" />
33
<MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench">
44
<Files>
5-
<File FileName="websocket-sharp/WebSocket.cs" Line="321" Column="66" />
5+
<File FileName="websocket-sharp/WebSocket.cs" Line="142" Column="22" />
66
</Files>
77
</MonoDevelop.Ide.Workbench>
88
<MonoDevelop.Ide.DebuggingService.Breakpoints>

websocket-sharp/Ext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static Byte[] InitializeWithPrintableASCII(this Byte[] bytes, Random rand
9393
return bytes;
9494
}
9595

96-
public static void NotEqualsDo(this string expected, string actual, Action<string, string> act)
96+
public static void AreNotEqualDo(this string expected, string actual, Action<string, string> act)
9797
{
9898
if (expected != actual)
9999
{

websocket-sharp/WebSocket.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,41 @@ public WebSocket(string url, string protocol)
129129
this.protocol = protocol;
130130
}
131131

132+
public WebSocket(
133+
string url,
134+
EventHandler onOpen,
135+
MessageEventHandler onMessage,
136+
MessageEventHandler onError,
137+
EventHandler onClose)
138+
: this(url, String.Empty, onOpen, onMessage, onError, onClose)
139+
{
140+
}
141+
142+
public WebSocket(
143+
string url,
144+
string protocol,
145+
EventHandler onOpen,
146+
MessageEventHandler onMessage,
147+
MessageEventHandler onError,
148+
EventHandler onClose)
149+
: this(url, protocol)
150+
{
151+
this.OnOpen += onOpen;
152+
this.OnMessage += onMessage;
153+
this.OnError += onError;
154+
this.OnClose += onClose;
155+
156+
Connect();
157+
}
158+
132159
public void Connect()
133160
{
161+
if (readyState == WsState.OPEN)
162+
{
163+
Console.WriteLine("WS: Info @Connect: Connection is already established.");
164+
return;
165+
}
166+
134167
createConnection();
135168
doHandshake();
136169

@@ -286,9 +319,10 @@ private void doHandshake()
286319
{
287320
throw new IOException("Invalid handshake response: " + a);
288321
};
289-
"HTTP/1.1 101 WebSocket Protocol Handshake".NotEqualsDo(response[0], act);
290-
"Upgrade: WebSocket".NotEqualsDo(response[1], act);
291-
"Connection: Upgrade".NotEqualsDo(response[2], act);
322+
323+
"HTTP/1.1 101 WebSocket Protocol Handshake".AreNotEqualDo(response[0], act);
324+
"Upgrade: WebSocket".AreNotEqualDo(response[1], act);
325+
"Connection: Upgrade".AreNotEqualDo(response[2], act);
292326

293327
for (int i = 3; i < response.Length; i++)
294328
{
@@ -305,13 +339,13 @@ private void doHandshake()
305339
string expectedResToHexStr = BitConverter.ToString(expectedRes);
306340
string actualResToHexStr = BitConverter.ToString(actualRes);
307341

308-
expectedResToHexStr.NotEqualsDo(actualResToHexStr, (e, a) =>
342+
expectedResToHexStr.AreNotEqualDo(actualResToHexStr, (e, a) =>
309343
{
310-
#if DEBUG
344+
#if DEBUG
311345
Console.WriteLine("WS: Error @doHandshake: Invalid challenge response.");
312346
Console.WriteLine("\texpected: {0}", e);
313347
Console.WriteLine("\tactual : {0}", a);
314-
#endif
348+
#endif
315349
throw new IOException("Invalid challenge response: " + a);
316350
});
317351

512 Bytes
Binary file not shown.
107 Bytes
Binary file not shown.
512 Bytes
Binary file not shown.
107 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)