本文整理汇总了C#中Server.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Run方法的具体用法?C# Server.Run怎么用?C# Server.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Run方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
using (var context = NetMQContext.Create())
{
var messageFactory = new MessageFactory();
var requestDispatcher = RequestDispatcher.Create().Register<RandomNumberRequest, int>(new RandomNumberRequestHandler());
var name = "ServerName";
Server server = new Server(new NetMQReceiverManager(context, "tcp://127.0.0.1:5556"), messageFactory, requestDispatcher, name);
Client client = new Client(new NetMQSenderManager(context, "tcp://127.0.0.1:5556"), messageFactory);
var cancellationTokenSource = new CancellationTokenSource();
var serverTask = Task.Run(() => server.Run(cancellationTokenSource.Token));
int response;
for (int i = 0; i < 10; i++)
{
response = client.Send<int, RandomNumberRequest>(new RandomNumberRequest() { Min = 10, Max = 100 });
Console.WriteLine(response);
}
cancellationTokenSource.Cancel();
}
}
示例2: Main
static void Main(string[] args)
{
//new Program().Run();
var srv = new Server<MyServerContext>();
srv.AddTask(new TcpServerTask());
srv.Run();
}
示例3: Run
public static void Run()
{
// server
using (var server = new Server()) {
server.Run();
// client
Extensions.RunInDomain(Client.Run);
}
}
示例4: Main
public static void Main(string[] args)
{
Server server = new Server();
server.Run();
foreach (Client client in Enumerable.Range(0, 5).Select(
x => new Client(string.Format("client {0}", x))))
{
client.Run();
}
Console.ReadLine();
}
示例5: OnStart
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
// create the server
server = new Server(
new TableStorageSiteUrlRepository(),
new WorkerRoleHubConfiguration()
);
// run the server
thread = new Thread(new ThreadStart(() => server.Run()));
thread.Start();
return base.OnStart();
}
示例6: Main
static void Main(string[] args)
{
var server = new Server(
new StaticSiteRepository(),
new ConsoleAppConfiguration()
);
var thread = new Thread(new ThreadStart(() => server.Run()));
thread.Start();
Console.WriteLine("Hit enter to exit");
Console.ReadLine();
Console.WriteLine("Exiting");
thread.Abort();
}
示例7: Main
private static void Main()
{
Server server = new Server();
server.Run();
}
示例8: Host
public Host(Node client, Server server)
{
_client = client;
_server = server;
_server.Run();
}
示例9: Main
//.........这里部分代码省略.........
XPathNavigator nav = config.CreateNavigator().SelectSingleNode("/server");
if (nav == null) {
Console.Error.WriteLine("Configuration file {0} has an invalid format: root <server> tag not found", filename);
Environment.Exit(1);
}
LogLevel logLevel = LogLevel.Info;
string logLevelAttribute = nav.GetAttribute("log-level", string.Empty);
if (logLevelAttribute != string.Empty) {
try {
logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), logLevelAttribute, true);
} catch (ArgumentException) {
Console.Error.WriteLine("Invalid log-level {0}", logLevelAttribute);
}
}
TextWriter logFileWriter = Console.Out;
string logFileAttribute = nav.GetAttribute("log", string.Empty);
if (logFileAttribute != string.Empty) {
string logFileName = Path.Combine(root, logFileAttribute);
StreamWriter writer = new StreamWriter(new FileStream(logFileName, FileMode.Append));
writer.AutoFlush = true;
logFileWriter = writer;
}
logger = new TextWriterLogger(logLevel, logFileWriter);
int port = 80;
IPAddress ip = IPAddress.Any;
string portAttribute = nav.GetAttribute("port", string.Empty);
string ipAttribute = nav.GetAttribute("interface", string.Empty);
if (portAttribute != string.Empty)
port = Convert.ToInt32(portAttribute);
if (ipAttribute != string.Empty) {
ip = GetAddress(ipAttribute);
if(ip == null) {
logger.Error("interface={0} but no local address has this prefix",ipAttribute);
Environment.Exit(1);
}
}
server = new Server(ip, port);
server.Log = logger;
Console.CancelKeyPress += new ConsoleCancelEventHandler(SignalExit);
XPathNodeIterator iterator = nav.SelectChildren("servlet", string.Empty);
while (iterator.MoveNext()) {
string context = iterator.Current.GetAttribute("context", string.Empty); // returns empty on missing --> "/"
if(!context.StartsWith("/"))
context = "/" + context;
if(!context.EndsWith("/"))
context = context + "/";
string className = iterator.Current.GetAttribute("class", string.Empty);
string assemblyName = iterator.Current.GetAttribute("assembly", string.Empty);
Dictionary<string, string> servletConfig = new Dictionary<string, string>();
XPathNodeIterator paramsIterator = iterator.Current.SelectChildren("param", string.Empty);
while (paramsIterator.MoveNext()) {
string name = paramsIterator.Current.GetAttribute("name", string.Empty);
if (name == null) {
logger.Error("<param> must have a name given.");
Environment.Exit(1);
}
servletConfig.Add(name, paramsIterator.Current.Value);
}
if (className == string.Empty) {
logger.Error("Servlet mapped to {0} has no class specified", context);
Environment.Exit(1);
}
if(assemblyName == string.Empty) {
logger.Error("Servlet mapped to {0} has no assembly specified", context);
Environment.Exit(1);
}
try {
Assembly assembly = Assembly.LoadFile(Path.GetFullPath(Path.Combine(root, assemblyName)));
Type type = assembly.GetType(className, true, true);
if (!type.IsSubclassOf(typeof(Servlet)))
throw new Exception(string.Format("Type {0} is not a subclass of {1}", type, typeof(Servlet)));
ConstructorInfo constructor = type.GetConstructor(new Type[0]);
Servlet servlet = (Servlet)constructor.Invoke(null);
servlet.Configuration = servletConfig;
server[context] = servlet;
} catch (Exception e) {
logger.Error("Couldn't instantiate class {0} from assembly {1}", className, assemblyName);
logger.Error(e);
Environment.Exit(1);
}
}
try {
server.Run();
} catch (Exception e) {
logger.Error("Server exception");
logger.Error(e);
Environment.Exit(2);
}
}
示例10: Main
public static void Main()
{
server = new Server();
server.Run();
}
示例11: SetUp
public void SetUp()
{
this.database = MockRepository.GenerateStub<IDatabaseAccessLayer>();
this.database.Stub(s => s.GetPerson(Arg<int>.Is.Equal(1))).Return(new Person { Id = 1 });
this.database.Stub(s => s.Login(Arg<LoginData>.Is.Equal(new LoginData("Login","Login")))).Return(new User("Login", "Login"));
this.service = MockRepository.GenerateStub<IWunschzettelService>();
this.service.Stub(s => s.GetPerson(Arg<int>.Is.Equal(1))).Return(new Person { Id = 1 });
this.serializer = MockRepository.GenerateStub<WunschzettelSerializer>();
this.server = new Server(this.database);
server.Run();
}
示例12: Main
static void Main(string[] args)
{
Server s = new Server();
s.Run();
}