本文整理汇总了C#中WebSocketServer.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer.Setup方法的具体用法?C# WebSocketServer.Setup怎么用?C# WebSocketServer.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocketServer
的用法示例。
在下文中一共展示了WebSocketServer.Setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//int port = int.Parse(args[0]);
int port = 443;
ServerConfig serverConfig = new ServerConfig
{
Name = "SecureSuperWebSocket",
Ip = "Any",
Port = port,
MaxRequestLength = 10485760,
SendingQueueSize = 500,
ReceiveBufferSize = 2050 * 1024,
//SendBufferSize = 600 * 1024,
};
socketServer = new WebSocketServer();
socketServer.NewSessionConnected += SocketServer_NewSessionConnected;
socketServer.NewDataReceived += SocketServer_NewDataReceived;
//socketServer.NewMessageReceived += SocketServer_NewMessageReceived;
socketServer.Setup(serverConfig);
socketServer.Start();
Console.WriteLine("Server is running on port {0} ...", port);
Console.ReadKey();
}
示例2: WebSocketInterface
public WebSocketInterface(int port, Session session)
{
_session = session;
var translations = session.Translation;
_server = new WebSocketServer();
_websocketHandler = WebSocketEventManager.CreateInstance();
var setupComplete = _server.Setup(new ServerConfig
{
Name = "NecroWebSocket",
Ip = "Any",
Port = port,
Mode = SocketMode.Tcp,
Security = "tls",
Certificate = new CertificateConfig
{
FilePath = @"cert.pfx",
Password = "necro"
}
});
if (setupComplete == false)
{
Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error);
return;
}
_server.NewMessageReceived += HandleMessage;
_server.NewSessionConnected += HandleSession;
_server.Start();
}
示例3: Main
static void Main(string[] args)
{
var config = new ServerConfig {
Name = "SuperWebSocket",
Ip = "Any",
Port = 2012,
Mode = SocketMode.Tcp,
};
Console.WriteLine("Starting WebSocketServer on port " + config.Port + "...");
var socketServer = new WebSocketServer();
socketServer.Setup(new RootConfig(), config);
socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
socketServer.NewSessionConnected += new SessionHandler<WebSocketSession>(socketServer_NewSessionConnected);
socketServer.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(socketServer_SessionClosed);
if (!socketServer.Start()) {
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
}
Console.WriteLine("The server started successfully, press 'q' key to stop it!");
while (Console.ReadKey().KeyChar != 'q') {
Console.WriteLine();
continue;
}
socketServer.Stop();
Console.WriteLine("\nThe server stopped!");
}
示例4: Run
public void Run()
{
//websocket init
Console.WriteLine("tetris server is starting... port:{0}", Port_WebSocket);
var listener = new WebSocketServer();
listener.NewMessageReceived += listener_NewMessageReceived;
listener.NewSessionConnected += listener_NewSessionConnected;
if (!listener.Setup(Port_WebSocket))
{
Console.WriteLine("failed to initialize.");
return;
}
if (!listener.Start())
{
Console.WriteLine("failed to start.");
return;
}
//transceiver init
Console.WriteLine("transceiver is starting... port:{0}", Port_Transceiver);
var tr = new Transceiver(null, 2013);
isRunning = true;
Thread th = new Thread(() =>
{
Packet p = new Packet();
while (isRunning)
{
p.Clear();
tr.Receive(ref p);
Console.WriteLine("received a packet: {0}", p.Peek());
if (conn != null)
{
try
{
conn.Send((string)p.Pop());
}
#pragma warning disable 0168
catch (Exception ex)
{
//conn = null;
}
#pragma warning restore 0168
}
}
tr.Dispose();
});
th.Start();
Console.WriteLine("press enter to terminate server.");
Console.ReadLine();
isRunning = false;
listener.Stop();
Console.WriteLine("terminating server...");
}
示例5: WebSocketInterface
public WebSocketInterface(int port)
{
_server = new WebSocketServer();
var setupComplete = _server.Setup(new ServerConfig
{
Name = "NecroWebSocket",
Ip = "Any",
Port = port,
Mode = SocketMode.Tcp,
Security = "tls",
Certificate = new CertificateConfig
{
FilePath = @"cert.pfx",
Password = "necro"
}
});
if (setupComplete == false)
{
Logger.Write($"Failed to start WebSocketServer on port : {port}", LogLevel.Error);
return;
}
_server.NewMessageReceived += HandleMessage;
_server.NewSessionConnected += HandleSession;
_server.Start();
}
示例6: socketServer_Initialize
static void socketServer_Initialize()
{
// Initialize the server object
SuperWebSocket.WebSocketServer socketServer = new WebSocketServer ();
// Initialize basic server configurations
SuperSocket.SocketBase.Config.RootConfig socketRootConfig = new SuperSocket.SocketBase.Config.RootConfig ();
SuperSocket.SocketBase.Config.ServerConfig socketServerConfig = new SuperSocket.SocketBase.Config.ServerConfig ();
SuperSocket.SocketEngine.SocketServerFactory socketServerFactory = new SuperSocket.SocketEngine.SocketServerFactory ();
// Set the name, IP address and port number which the server is started on
socketServerConfig.Name = "Quetzalcoatl Server";
socketServerConfig.Ip = "127.0.0.1";
socketServerConfig.Port = 1620;
// Print boilerplate text when the console is first displayed
logConsoleBoilerplate ();
// Create the server using the specifications created above
// If the server fails to start, write to the console
if (!socketServer.Setup (socketRootConfig, socketServerConfig, socketServerFactory)) {
Console.WriteLine ("Failed to initialize server at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port);
Console.ReadKey ();
return;
}
// Start the server
// If the server fails to start, write to the console
if (!socketServer.Start ()) {
Console.WriteLine ("Server was successfully initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port +
" but failed to start. Ensure that no processes are currently running at the same address.");
Console.ReadKey ();
return;
}
// Notify the user that the server has successfully started and is awaiting connections
Console.WriteLine ("Server initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port + " at " + socketServer.StartedTime);
Console.WriteLine ("Awaiting client connections...");
Console.WriteLine ();
// Bind listeners for server events
socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string> (socketServer_NewMessageReceived);
socketServer.NewSessionConnected += socketServer_NewSessionConnected;
socketServer.SessionClosed += socketServer_SessionClosed;
// Nullify all console inputs except for when the user types "exit"
while (Console.ReadLine () != "exit") {
continue;
}
// Properly shutdown the server by waiting on the buffer and freeing all used ports
socketServer_Shutdown (socketServer);
return;
}
示例7: Main
static void Main(string[] arguments)
{
WebSocketServer server = new WebSocketServer();
server.NewSessionConnected += new SessionHandler<WebSocketSession>(OnConnect);
server.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(OnDisconnect);
server.NewMessageReceived += new SessionHandler<WebSocketSession, string>(OnMessage);
server.Setup(81);
server.Start();
ManualResetEvent resetEvent = new ManualResetEvent(false);
resetEvent.WaitOne();
}
示例8: Setup
public virtual void Setup()
{
m_WebSocketServer = new WebSocketServer(new BasicSubProtocol("Basic", new List<Assembly> { this.GetType().Assembly }));
m_WebSocketServer.Setup(new ServerConfig
{
Port = 2012,
Ip = "Any",
MaxConnectionNumber = 100,
Mode = SocketMode.Tcp,
Name = "SuperWebSocket Server"
}, logFactory: new ConsoleLogFactory());
}
示例9: MainServer
public MainServer(IPAddress address, int port)
{
server = new WebSocketServer();
//Events
server.Setup(2480);
server.NewSessionConnected += new SessionHandler<WebSocketSession>(OnConnected);
server.SessionClosed += new SessionHandler<WebSocketSession,CloseReason>(OnDisconnect);
//server.NewRequestReceived += new RequestHandler<WebSocketSession,SuperWebSocket.Protocol.IWebSocketFragment>(OnConnect);
server.NewMessageReceived += new SessionHandler<WebSocketSession,string>(OnMessage);
server.Start();
MainGame = new Game();
MainGame.StartGame();
}
示例10: StartSuperWebSocketByProgramming
public void StartSuperWebSocketByProgramming()
{
var socketServer = new WebSocketServer();
socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
socketServer.NewSessionConnected += socketServer_NewSessionConnected;
socketServer.SessionClosed += socketServer_SessionClosed;
socketServer.Setup(port);
m_Bootstrap = new DefaultBootstrap(new RootConfig(), new IWorkItem[] { socketServer });
m_Bootstrap.Start();
}
示例11: Main
static void Main()
{
try
{
SingleInstanceChecker.checkThePowerRunning();
tomcatController = new EmbeddedTomcatController();
nativeID = Guid.NewGuid();
portalID = Guid.NewGuid();
websocketserver = new WebSocketServer();
int port = Int32.Parse(ConfigurationManager.AppSettings["WebSocketPort"]);
if (!websocketserver.Setup(port))
{
throw new Exception("ERROR:" + port + " already used!");
}
for (int i = 0; i < 3; i++ )
{
if (!websocketserver.Start())
{
EmbeddedTomcatController.killExist();
continue;
}
else {
break;
}
throw new Exception("ERROR:Failed to start server!");
}
websocketserver.NewMessageReceived += websocketserver_NewMessageReceived;
}
catch (Exception e)
{
logger.Error(e.Message, e);
MessageBox.Show(e.Message);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
tomcatController.startTomcat();
nativeContainer = new NativeContainer();
nativeContainer.FormClosing += nativeContainer_FormClosing;
splash = new SplashForm();
nativeContainer.Splash = splash;
splash.start();
nativeContainer.initPortalKitUrl();
Application.Run(splash);
}
示例12: Main
public static void Main()
{
server = new WebSocketServer();
server.NewMessageReceived += ServerOnNewMessageReceived;
server.NewSessionConnected += ServerOnNewSessionConnected;
server.Setup(4521);
server.Start();
Console.WriteLine("Running ... press any key to exit");
Console.ReadKey(true);
server.Stop();
}
示例13: WebSocket
public WebSocket()
{
_webSocketServer = new WebSocketServer();
_webSocketServer.NewMessageReceived += _webSocketServer_NewMessageReceived;
_webSocketServer.NewSessionConnected += _webSocketServer_NewSessionConnected;
_webSocketServer.Setup(new RootConfig(), new ServerConfig
{
Port = 2013,
Ip = "Any",
MaxConnectionNumber = 10000,
Mode = SocketMode.Async,
Name = "MAGUS Async Core"
}, SocketServerFactory.Instance);
}
示例14: Setup
protected void Setup(WebSocketServer websocketServer, Action<ServerConfig> configurator)
{
var rootConfig = new RootConfig { DisablePerformanceDataCollector = true };
websocketServer.NewSessionConnected += new SessionHandler<WebSocketSession>(m_WebSocketServer_NewSessionConnected);
websocketServer.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(m_WebSocketServer_SessionClosed);
var config = new ServerConfig();
configurator(config);
var ret = websocketServer.Setup(rootConfig, config, null, null, new ConsoleLogFactory(), null, null);
Assert.IsTrue(ret);
m_WebSocketServer = websocketServer;
}
示例15: WebSocketCoreBusServer
public WebSocketCoreBusServer(int listenPort, ICoreBusClientIdExtractor coreBusClientIdExtractor = null)
: base(coreBusClientIdExtractor)
{
_appServer = new WebSocketServer();
if (!_appServer.Setup(listenPort))
{
throw new Exception("Failed to setup WebSocketServer");
}
if (!_appServer.Start())
{
throw new Exception("Failed to start WebSocketServer");
}
_appServer.NewMessageReceived += _onNewMessageReceived;
_appServer.SessionClosed += _onSessionClosed;
}