Skip to content
This repository has been archived by the owner on Oct 19, 2019. It is now read-only.

Commit

Permalink
re-organize the samples projects
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed May 19, 2013
1 parent 09d9179 commit 4c383f6
Show file tree
Hide file tree
Showing 34 changed files with 271 additions and 510 deletions.
24 changes: 12 additions & 12 deletions Samples.sln
Expand Up @@ -8,8 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{648A0D
GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperWebSocketWeb", "Samples\SuperWebSocketWeb\SuperWebSocketWeb.csproj", "{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C-StartByConfig-CommandAssembly", "Samples\CommandAssembly\C-StartByConfig-CommandAssembly.csproj", "{4A8713F5-DF02-4424-81F2-D112C615ADC2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "F-JsonCommandAssembly", "Samples\JsonCommandAssembly\F-JsonCommandAssembly.csproj", "{31511A5E-6A0E-4DA3-AD7A-8C239634AF8A}"
Expand Down Expand Up @@ -44,6 +42,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "D-StartBy(SuperSocket.Socke
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperWebSocketTest", "SuperWebSocketTest\SuperWebSocketTest.csproj", "{9EF7E84D-B746-4285-A89A-5A515AB540EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "G-LiveChatWeb", "Samples\LiveWebChat\G-LiveChatWeb.csproj", "{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -64,16 +64,6 @@ Global
{2DC79E40-BB70-4F6A-B378-905F2FBC6E97}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2DC79E40-BB70-4F6A-B378-905F2FBC6E97}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2DC79E40-BB70-4F6A-B378-905F2FBC6E97}.Release|x86.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|x86.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Any CPU.Build.0 = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|x86.ActiveCfg = Release|Any CPU
{4A8713F5-DF02-4424-81F2-D112C615ADC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A8713F5-DF02-4424-81F2-D112C615ADC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A8713F5-DF02-4424-81F2-D112C615ADC2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -144,6 +134,16 @@ Global
{9EF7E84D-B746-4285-A89A-5A515AB540EA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9EF7E84D-B746-4285-A89A-5A515AB540EA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9EF7E84D-B746-4285-A89A-5A515AB540EA}.Release|x86.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Debug|x86.ActiveCfg = Debug|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Any CPU.Build.0 = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9BA4110E-41D7-491B-9BAD-50C0EB10CFBC}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
@@ -1,4 +1,4 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SuperWebSocketWeb.Default" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SuperWebSocket.Samples.LiveWebChat.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Expand Down
Expand Up @@ -5,7 +5,7 @@
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SuperWebSocketWeb
namespace SuperWebSocket.Samples.LiveWebChat
{
public partial class Default : System.Web.UI.Page
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -10,8 +10,8 @@
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SuperWebSocketWeb</RootNamespace>
<AssemblyName>SuperWebSocketWeb</AssemblyName>
<RootNamespace>SuperWebSocket.Samples.LiveWebChat</RootNamespace>
<AssemblyName>SuperWebSocket.Samples.LiveWebChat</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
Expand Down Expand Up @@ -124,9 +124,6 @@
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="supersocket.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="localhost.pfx" />
</ItemGroup>
Expand Down
@@ -1 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="SuperWebSocketWeb.Global" Language="C#" %>
<%@ Application Codebehind="Global.asax.cs" Inherits="SuperWebSocket.Samples.LiveWebChat.Global" Language="C#" %>
102 changes: 102 additions & 0 deletions Samples/LiveWebChat/Global.asax.cs
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperSocket.SocketEngine;
using SuperSocket.SocketEngine.Configuration;
using SuperWebSocket;

namespace SuperWebSocket.Samples.LiveWebChat
{
public class Global : System.Web.HttpApplication
{
private IBootstrap m_Bootstrap;
private WebSocketServer m_WebSocketServer;

void Application_Start(object sender, EventArgs e)
{
StartSuperWebSocketByConfig();
}

void StartSuperWebSocketByConfig()
{
m_Bootstrap = BootstrapFactory.CreateBootstrap();

if (!m_Bootstrap.Initialize())
return;

var socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SuperWebSocket")) as WebSocketServer;

socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
socketServer.NewSessionConnected += socketServer_NewSessionConnected;
socketServer.SessionClosed += socketServer_SessionClosed;

m_WebSocketServer = socketServer;

m_Bootstrap.Start();
}

void socketServer_NewMessageReceived(WebSocketSession session, string e)
{
SendToAll(session.Cookies["name"] + ": " + e);
}

void socketServer_NewSessionConnected(WebSocketSession session)
{
SendToAll("System: " + session.Cookies["name"] + " connected");
}

void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
{
if (reason == CloseReason.ServerShutdown)
return;

SendToAll("System: " + session.Cookies["name"] + " disconnected");
}

void SendToAll(string message)
{
foreach (var s in m_WebSocketServer.GetAllSessions())
{
s.Send(message);
}
}

void Application_End(object sender, EventArgs e)
{
if (m_Bootstrap != null)
m_Bootstrap.Stop();
}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started

}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

}

}
}
@@ -1,4 +1,4 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LiveChat.aspx.cs" Inherits="SuperWebSocketWeb.LiveChat" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LiveChat.aspx.cs" Inherits="SuperWebSocket.Samples.LiveWebChat.LiveChat" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
Expand Down Expand Up @@ -68,7 +68,7 @@
messageBoard.append("* Connecting to server ..<br/>");
// create a new websocket and connect
ws = new window[support]('ws://<%= Request.Url.Host %>:<%= WebSocketPort %>/sample');
ws = new window[support]('ws://<%= Request.Url.Host %>:8080/sample');
// when data is comming from the server, this metod is called
ws.onmessage = function (evt) {
Expand All @@ -85,25 +85,6 @@
ws.onclose = function () {
messageBoard.append('* Connection closed<br/>');
}
//setup secure websocket
var wss = new window[support]('wss://<%= Request.Url.Host %>:<%= SecureWebSocketPort %>/sample');
// when data is comming from the server, this metod is called
wss.onmessage = function (evt) {
messageBoard.append("# " + evt.data + "<br />");
scrollToBottom(messageBoard);
};
// when the connection is established, this method is called
wss.onopen = function () {
messageBoard.append('* Secure Connection open<br/>');
};
// when the connection is closed, this method is called
wss.onclose = function () {
messageBoard.append('* Secure Connection closed<br/>');
}
}
function sendMessage() {
Expand Down
21 changes: 21 additions & 0 deletions Samples/LiveWebChat/LiveChat.aspx.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace SuperWebSocket.Samples.LiveWebChat
{
public partial class LiveChat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var nameCookie = Request.Cookies.Get("name");

if (nameCookie == null)
Response.Redirect("~/Default.aspx?returnUrl=" + Server.UrlEncode(Request.FilePath));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,4 +1,4 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LiveChatWithBridge.aspx.cs" Inherits="SuperWebSocketWeb.LiveChatWithBridge" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LiveChatWithBridge.aspx.cs" Inherits="SuperWebSocket.Samples.LiveWebChat.LiveChatWithBridge" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
Expand Down Expand Up @@ -61,7 +61,7 @@
messageBoard.append("* Connecting to server ..<br/>");
// create a new websocket and connect
var websocket = new WebSocketEx('ws://<%= Request.Url.Host %>:<%= WebSocketPort %>/sample', '', function () {
var websocket = new WebSocketEx('ws://<%= Request.Url.Host %>:4502/sample', '', function () {
messageBoard.append('* Connection open<br/>');
ws = websocket;
}, function () {
Expand Down
Expand Up @@ -6,7 +6,7 @@
using System.Web.UI.WebControls;
using System.Configuration;

namespace SuperWebSocketWeb
namespace SuperWebSocket.Samples.LiveWebChat
{
public partial class LiveChatWithBridge : System.Web.UI.Page
{
Expand All @@ -17,18 +17,5 @@ protected void Page_Load(object sender, EventArgs e)
if (nameCookie == null)
Response.Redirect("~/Default.aspx?returnUrl=" + Server.UrlEncode(Request.FilePath));
}

protected object WebSocketPort
{
get
{
var extPort = ConfigurationManager.AppSettings["extPort"];

if (string.IsNullOrEmpty(extPort))
return Application["WebSocketPort"];
else
return extPort;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Samples/LiveWebChat/Push.aspx
@@ -0,0 +1,34 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Push.aspx.cs" Inherits="SuperWebSocketWeb.Push" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script language="javascript" type="text/javascript">
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
xmlhttp.open("POST", "Push.aspx?Pooling=true", true);
xmlhttp.send();
</script>
</div>
</form>
</body>
</html>

0 comments on commit 4c383f6

Please sign in to comment.