private static void Main(string[] args) { // Log everything to console. LogFactory.Assign(new ConsoleLogFactory(null)); Assembly thisAssembly = typeof(Program).Assembly; // create a MVC web server. var server = new MvcServer(); server.ViewEngines.Add(new NHamlViewEngine()); server.Add(HttpListener.Create(IPAddress.Any, 8080)); server.Add(new SimpleRouter("/", "/user/")); // Load controllers and embedded views. BootStrapper bootStrapper = new BootStrapper(server); bootStrapper.LoadEmbeddedViews(thisAssembly); bootStrapper.LoadControllers(thisAssembly); server.Start(5); // run until you press enter. Console.ReadLine(); }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); ServiceHostInfo info = new ServiceHostInfo(); info.Name = ConfigurationMaster.Get(ServiceConfiguration.DefaultServiceConfigurationName); info.Address = Dns.GetHostName(); info.Port = int.Parse(ConfigurationMaster.Get(ServiceConfiguration.DefaultServicePortConfigurationName)); info.Binding = new NetTcpBinding(ServiceConfiguration.DefaultNetTcpBindingName); info.Contract = typeof(IDeviceConnectorService); info.Service = typeof(DeviceConnectorService); Console.WriteLine(string.Format(@"Service is starting on [{0}]", info.ToString())); ManagedServiceHostActivator <IDeviceConnectorService> activator = new ManagedServiceHostActivator <IDeviceConnectorService>(info); activator.Start(); Console.WriteLine(string.Format(@"Service address [{0}]", activator.ServiceHost.Description.Endpoints.First().Address)); Console.WriteLine(); Console.WriteLine("Press any key to close service."); Console.ReadKey(); activator.Stop(); }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999); IPEndPoint localEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9998); // 测试用,可以不指定由系统选择端口 client = new AsyncTcpClient(remoteEP, localEP); client.Encoding = Encoding.UTF8; client.ServerExceptionOccurred += new EventHandler <TcpServerExceptionOccurredEventArgs>(client_ServerExceptionOccurred); client.ServerConnected += new EventHandler <TcpServerConnectedEventArgs>(client_ServerConnected); client.ServerDisconnected += new EventHandler <TcpServerDisconnectedEventArgs>(client_ServerDisconnected); client.PlaintextReceived += new EventHandler <TcpDatagramReceivedEventArgs <string> >(client_PlaintextReceived); client.Connect(); Console.WriteLine("TCP client has connected to server."); Console.WriteLine("Type something to send to server..."); while (true) { try { string text = Console.ReadLine(); client.Send(text); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); byte[] datagram = new byte[277777]; for (int i = 0; i < datagram.Length; i++) { datagram[i] = 1; } ICollection <UdpPacket> packets = UdpPacketSplitter.Split(1024, datagram, 65535); foreach (var packet in packets) { Console.WriteLine(packet.ToString()); } foreach (var packet in packets) { byte[] data = packet.ToArray(); UdpPacket convert = UdpPacket.FromArray(data); Console.WriteLine(convert.ToString()); } Console.ReadKey(); }
public FrmMain() { log = flf.CreateLogger(); try { InitializeComponent(); dic = new ProcessControVariables().SetKeyValue(); LogFactory.Assign(new ConsoleLogFactory()); // 异步通讯初始化 端口10001 编码UTF8 server = new AsyncTcpServer(10001); server.Encoding = Encoding.UTF8; // 客户端连接事件 server.ClientConnected += new EventHandler <TcpClientConnectedEventArgs>(server_ClientConnected); // 客户端断开事件 server.ClientDisconnected += new EventHandler <TcpClientDisconnectedEventArgs>(server_ClientDisconnected); // 接受string类型电文事件 server.PlaintextReceived += new EventHandler <TcpDatagramReceivedEventArgs <string> >(server_PlaintextReceived); // 接受byte[]类型电文事件 server.DatagramReceived += new EventHandler <TcpDatagramReceivedEventArgs <byte[]> >(server_DatagramReceived); frmMM.ManualOperationOrders += FrmMM_ManualOperationOrders; // 启动服务程序 server.Start(); } catch (Exception ex) { log.Exception(ex); } }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.Title = "Web Server"; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" Rains Soft Web Server"); Console.WriteLine(" Rains Soft"); Console.WriteLine(" http://www.mobanhou.com"); Console.WriteLine(); Console.ResetColor(); int i = 0; while (true) { if (i > 9) { Console.WriteLine("."); break; } else { Console.Write("."); i++; } System.Threading.Thread.Sleep(500); } var filter = new LogFilter(); filter.AddStandardRules(); var log = new ConsoleLogFactory(filter); LogFactory.Assign(log); Logger = LogFactory.CreateLogger(log.GetType()) as ConsoleAndTextLogger; Logger.Info("create server"); // create a server. var server = new Server(); // same as previous example. var module = new FileModule(); module.Resources.Add(new FileResources("/", Environment.CurrentDirectory + "\\files\\")); server.Add(module); server.Add(new CustomHttpModule()); server.RequestReceived += OnRequest; server.Add(new MultiPartDecoder()); // use one http listener. server.Add(HttpListener.Create(IPAddress.Any, 8085)); server.Add(new SimpleRouter("/", "/index.html")); Logger.Info("start server"); // start server, can have max 5 pending accepts. server.Start(5); Console.Beep(); Console.ReadLine(); }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); ServiceProvider.Bootstrap(); ServiceHostInfo info = new ServiceHostInfo(); info.Name = ConfigurationMaster.Get(ServiceConfiguration.DefaultServiceConfigurationName); info.Address = Dns.GetHostName(); info.Port = int.Parse(ConfigurationMaster.Get(ServiceConfiguration.DefaultServicePortConfigurationName)); info.Binding = new NetTcpBinding(ServiceConfiguration.DefaultNetTcpBindingName); info.Contract = typeof(IDeviceProfileService); info.Service = typeof(DeviceProfileService); Console.WriteLine(string.Format(@"Service is starting on [{0}]", info.ToString())); ManagedServiceHostActivator <IDeviceProfileService> activator = new ManagedServiceHostActivator <IDeviceProfileService>(info); activator.Start(); Console.WriteLine(string.Format(@"Service address [{0}]", activator.ServiceHost.Description.Endpoints.First().Address)); string serverName = ConfigurationMaster.Get(@"HttpServerName"); string httpServerName = serverName + " HTTP Server"; int httpBindingPort = int.Parse(ConfigurationMaster.Get(@"HttpServerPort")); Server server = null; server = new Server(httpServerName); server.Add(HttpListenerFactory.Create(IPAddress.Any, httpBindingPort)); server.Add(new CameraListModule()); server.Add(new CameraModule()); server.Add(new CameraThumbnailModule()); FileModule fileModule = new FileModule(); EmbeddedResourceLoader embedded = new EmbeddedResourceLoader(); embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".Resources.favicon.ico"); fileModule.Resources.Add(embedded); server.Add(fileModule); server.Add(new SimpleRouter("/favicon.ico", "/resources/favicon.ico")); server.Start(5); Console.WriteLine(string.Format("Start {0} on {1}.", httpServerName, httpBindingPort)); Console.WriteLine(); Console.WriteLine("Press any key to close service."); Console.ReadKey(); server.Stop(true); activator.Stop(); }
public MessageFactoryTest() { LogFactory.Assign(new ConsoleLogFactory(null)); _headerFactory = new HeaderFactory(); _headerFactory.AddDefaultParsers(); _factory = new MessageFactory(_headerFactory); _factory.RequestReceived += OnRequest; _factory.ResponseReceived += OnResponse; }
public NancyHost(IPAddress address, int port, INancyBootstrapper bootStrapper) { var filter = new LogFilter(); filter.AddStandardRules(); LogFactory.Assign(new ConsoleLogFactory(filter)); server = new Server(); bootStrapper.Initialise(); engine = bootStrapper.GetEngine(); // same as previous example. AppiaModule module = new AppiaModule(engine); server.Add(module); }
public UdpTransportTest() { LogFactory.Assign(new ConsoleLogFactory(null)); var headerFactory = new HeaderFactory(); headerFactory.AddDefaultParsers(); _messageFactory = new MessageFactory(headerFactory); _messageFactory.RequestReceived += OnRequest; _messageFactory.ResponseReceived += OnResponse; var pool = new ObjectPool <byte[]>(CreateBuffer); _transport = new UdpTransport(new IPEndPoint(IPAddress.Loopback, PortNumber), _messageFactory) { BufferPool = _bufferPool }; _transport.Start(); _transport.UnhandledException += OnUnhandledException; }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); server.Start(); Logger.Debug("StreamingServer is running..."); DesktopVideoSource source = new DesktopVideoSource(0); source.FrameInterval = 50; source.IsResized = true; source.ResizeWidth = 600; source.ResizeHeight = 450; source.NewFrame += new NewFrameEventHandler(OnNewFrame); source.Start(); Logger.Debug("VideoSource is running..."); Console.ReadLine(); }
static void Main(string[] args) { LogFactory.Assign(new ConsoleLogFactory()); server = new AsyncTcpServer(9999); server.Encoding = Encoding.UTF8; server.ClientConnected += new EventHandler <TcpClientConnectedEventArgs>(server_ClientConnected); server.ClientDisconnected += new EventHandler <TcpClientDisconnectedEventArgs>(server_ClientDisconnected); server.PlaintextReceived += new EventHandler <TcpDatagramReceivedEventArgs <string> >(server_PlaintextReceived); server.Start(); Console.WriteLine("TCP server has been started."); Console.WriteLine("Type something to send to client..."); while (true) { string text = Console.ReadLine(); server.SendToAll(text); } }
private static void Main(string[] args) { var filter = new LogFilter(); filter.AddNamespace("SipSharp.Transports.*", LogLevel.Debug); filter.AddStandardRules(); LogFactory.Assign(new ConsoleLogFactory(filter)); var repos = new RegistrationRepository(); repos.Add(new SipUri("*****@*****.**"), "u1000067"); SwitchSharp switchSharp = new SwitchSharp(); switchSharp.RegistrationDatabase = repos; switchSharp.AddListener(new UdpTransport(new IPEndPoint(IPAddress.Any, 5060), switchSharp.MessageFactory)); switchSharp.Start("mydomain.com"); Thread.Sleep(500000); }
public TcpTransportTestFixture() { LogFactory.Assign(new ConsoleLogFactory(null)); }
static App() { LogFactory.Assign(new ConsoleLogFactory()); DispatcherHelper.Initialize(); ServiceProvider.Bootstrap(); }