using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace testform
{
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using DotNetty.Codecs;
using DotNetty.Handlers.Logging;
using DotNetty.Handlers.Tls;
using DotNetty.Transport.Bootstrapping;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Sockets;
using Examples.Common;
using System.Collections.Concurrent;
using System.Threading; class RunServerto
{
//private static BlockingCollection<MesServer> bcms = new BlockingCollection<MesServer>(); //public static string userId { get; internal set; }
//public static string SAY_WELCOME { get; internal set; }
//public static string BYE { get; internal set; } //public static readonly string Content = "消息内容";
//public static readonly string serverId = "Endv Cn Server";//当前托管线程的唯一标识符
//public static readonly int WAIT = 20000;
//internal static readonly string SAY_THANKS;
//internal static readonly string WHAT;
//internal static string TASK; public static void Main(string [] args)
{
Parallel.Invoke(
() =>
{
Form3 form3 = new Form3();
form3.Show();
//Console.WriteLine("任务1……");
},
() =>
{
//RunServerAsync().Wait();
Task thread2 = new Task(() => { RunServerAsync().Wait(); });//创建新线程
thread2.Start();
//RunServerAsync();
}); //Console.ReadKey();
//Form1 form1 = new Form1();
////消费者线程
//ParallelOptions po = new ParallelOptions();
//po.MaxDegreeOfParallelism = -1;
//Parallel.Invoke(po, () => {
// ////////////////////////////////////////
// //int threadid = Environment.CurrentManagedThreadId;
// //MesServer server = new MesServer();
// //while(true)
// //{
// form1.textBox2.Text = "1234567form1";
// form1.Show(); // 尝试在指定的时间段内从 server 中移除一个项
//if(bcms.TryTake(out server, RunServerto.WAIT))
//{
// server.ThreadID = threadid;
// server.doAction();
// //Console.WriteLine(" ");
// //Console.WriteLine(server.ToString(false)); //}
//else
//{
// if(server == null)
// {
// server = new MesServer();
// }
// server.ThreadID = threadid;
// server.content = Content;
// //Console.WriteLine(server.ToString(false));
//}
//}
//},
//////////////////////////////////////////
//() => { //int prdID = Environment.CurrentManagedThreadId;
//MesServer server = new MesServer();
//server.ProductorID = prdID;
//server.content = Content;
////Console.WriteLine(productor.ToString(true));
//while(true)
//{
// Form3 form3 = new Form3();
// form3.Show();
// form3.label1.Text = "";
// //Console.Write("Productor Behavior (i.e. say,hello) : ");
// //string msgContent = Console.ReadLine(); // form3.textBox2.Text="打开窗体3";
// string msgContent = form3.textBox2.Text ;
// server = new MesServer();
// server.ProductorID = prdID;
// //:“索引超出了数组界限。” // //server.key = msgContent.Split(',') [0];
// //server.content = msgContent.Split(',') [1];
// bcms.Add(server); //Thread thread1 = new Thread(() => { threadPro(); });//创建新线程
//thread1.Start();
//Thread thread2= new Thread(() => { MesServer.RunServerAsync().Wait(); });//创建新线程
//thread2.Start();
//MesServer.RunServerAsync().Wait();
//} //}); }
public static async Task RunServerAsync()
{
//在控制台命令中启用日志
//ExampleHelper.SetConsoleLogger();
Form1 form1 = new Form1();
form1.Show();
//多线程事件循环组,创建一个新实例,老板组
var bossGroup = new MultithreadEventLoopGroup();
//多线程事件循环组,创建一个新实例,工作组
var workerGroup = new MultithreadEventLoopGroup(); //字符串编码
var STRING_ENCODER = new StringEncoder();
//字符串解码
var STRING_DECODER = new StringDecoder();
//安全聊天服务器处理程序
var SERVER_HANDLER = new SecureChatServerHandler(); X509Certificate2 tlsCertificate = null;
if(ServerSettings.IsSsl)
{
// 创建 X.509 证书
tlsCertificate = new X509Certificate2(Path.Combine(ExampleHelper.ProcessDirectory, "dotnetty.com.pfx"), "password");
}
try
{
//服务器启动
var bootstrap = new ServerBootstrap();
bootstrap
.Group(bossGroup, workerGroup)
//服务器套接字通道
.Channel<TcpServerSocketChannel>()
//所以返回日志
.Option(ChannelOption.SoBacklog, )
//Handler用于服务请求 “信息”日志级别。
.Handler(new LoggingHandler(LogLevel.INFO))
//设置{@链接channelhandler }这是用来服务请求{@链接通道}的。
.ChildHandler(
new ActionChannelInitializer<ISocketChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
if(tlsCertificate != null)
{
//添加协议到最后
pipeline.AddLast(TlsHandler.Server(tlsCertificate));
}
//添加基于行分隔符的帧解码器到最后
pipeline.AddLast(new DelimiterBasedFrameDecoder(, Delimiters.LineDelimiter()));
pipeline.AddLast(STRING_ENCODER, STRING_DECODER, SERVER_HANDLER);
}));
// 创建异步通道并绑定异步端口
IChannel bootstrapChannel = await bootstrap.BindAsync(ServerSettings.Port);
form1.textBox2.Text = "IChannel线程已启动";
//Console.ReadLine();
//关闭异步
await bootstrapChannel.CloseAsync();
}
finally
{
// 等待提供的所有 System.Threading.Tasks.Task 对象完成执行过程
Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync());
}
} //static void threadPro()
//{
// //this. form3.Show();
//}
} class MesServer
{ //public int ThreadID { get; internal set; }//当前托管线程的唯一标识符
////public string userId { get; set; }
//public string key { get; set; }
//public string content { get; set; }
//public int ProductorID { get; internal set; } //public void doAction()
//{
// //比较
// if(string.Compare(key, RunServerto.userId) == 0)
// { Form1 form2 = new Form1();
// content = string.Compare(content, RunServerto.SAY_THANKS) == 0 ? RunServerto.SAY_WELCOME : RunServerto.WHAT; // form2.Show();
// } // if(string.Compare(key, RunServerto.TASK) == 0)
// {
// Task taskA = Task.Factory.StartNew(() => {
// //Main2().Show();
// //Console.WriteLine("task A begin ");
// Task ChildOfFatehrA = Task.Factory.StartNew(() => {
// //Console.WriteLine("Sub task A begin ");
// //Thread.Sleep(1000);
// //Console.WriteLine("Sub task A end ");
// //Main2().Show();
// Form4 form4 = new Form4();
// form4.textBox2.Text = "打开窗体4";
// //string msgContent = form3.textBox2.Text; // });
// ChildOfFatehrA.Wait();
// Console.WriteLine("task A end "); // });
// taskA.ContinueWith(taskB => {
// //Console.WriteLine("task B begin ");
// //Thread.Sleep(5000);
// //Console.WriteLine("task B end ");
// });
// taskA.Wait();
// } //} }
}

testform的更多相关文章

  1. 12、Struts2表单重复提交

    什么是表单重复提交 表单的重复提交: 若刷新表单页面, 再提交表单不算重复提交. 在不刷新表单页面的前提下: 多次点击提交按钮 已经提交成功, 按 "回退" 之后, 再点击 &qu ...

  2. JavaScript特性(attribute)、属性(property)和样式(style)

    最近在研读一本巨著<JavaScript忍者秘籍>,里面有一篇文章提到了这3个概念. 书中的源码可以在此下载.我将源码放到了线上,如果不想下载,可以直接访问在线网址,修改页面名就能访问到相 ...

  3. Javascript本地存储小结

    前言 总括:详细讲述Cookie,LocalStorge,SesstionStorge的区别和用法. 人生如画,岁月如歌. 原文博客地址:Javascript本地存储小结 知乎专栏&& ...

  4. PHP跨域form提交

    因为安全性因素,直接跨域访问是不被允许的. 1.PHP CURL方式 function curlPost($url,$params) { $postData = ''; foreach($params ...

  5. ajax+div 代替iframe 学习尝试

    工作的时候遇到了所谓html内多tab展示的情况,主要是通过iframe来关联子页面: 不过也不知道从何时开始记得是说iframe不建议多用,所以想想,还是找找有没有其他方法(不应用于工作): 先说下 ...

  6. session跟cookie的区别

    这些都是基础知识,不过有必要做深入了解.先简单介绍一下. 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择, 都纪 ...

  7. js 预处理用户上传图片

    前几个月闲得无聊写得一段代码,没想最近刚好用上了,在硬盘里翻了半天找回来,还没好好整理直接用上了手机用户拍照上传的图片一般都在1M 到4M 之间,如果只是用作头像尺寸就可以缩小很多,1M甚至几M的图转 ...

  8. struts.xml的编辑

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...

  9. Winform 生成不需要安装的exe可执行文件 ILMerge使用

    今天应领导要求,把一个程序打包生成一个可以执行的exe文件,不是安装包那种,类似于绿色文件,就是一个exe,可以直接运行.上网查了一下有一个工具可以实现ILMerge. 参照两个文档http://bl ...

随机推荐

  1. flask+gunicorn中文文件下载报错问题及解决

    导言 问题源起与一个静态文件下载的接口: from flask import Flask, current_app app = Flask(__name__) @app.route('/file_na ...

  2. Idea设置全白色 背景

    IDEA设置全白色背景 标签(空格分隔): 工具使用 编辑框白色设置 菜单栏白色设置

  3. eclipse怎么关闭spring dashboard

    进入help-install new software-what is already installed?-卸载spring board

  4. shell字符串变量的特异功能:字符串的替换(${str/源模式/目标模式},${str//源模式/目标模式})、截断

    https://blog.csdn.net/wzb56_earl/article/details/6953612

  5. 内存可见性,指令重排序,JIT。。。。。。从一个知乎问题谈起

    在知乎上看到一个问题<java中volatile关键字的疑惑?>,引起了我的兴趣 问题是这样的: package com.cc.test.volatileTest; public clas ...

  6. c# 使用ssh连接远程主机(ssh.net演示)

    本教程使用的是ssh.net这个库.项目地址:https://github.com/sshnet/SSH.NET 使用ssh客户端连接远程主机执行命令,并拿到输出结果: using (var sshC ...

  7. JavaScript代码放在head和body的区别(QRCode生成)

    1.在head中时,所代表的functions只加载而不执行,执行是在某一事件触发后才开始. 2.在body中时,直接加载并执行 典型的区别: 如果有不在函数中的执行语句,比如变量初始化,如果在hea ...

  8. 训练指南 UVA - 11419(二分图最小覆盖数)

    layout: post title: 训练指南 UVA - 11419(二分图最小覆盖数) author: "luowentaoaa" catalog: true mathjax ...

  9. poj2778(AC 自动机)

    poj2778 题意 构造只包含 \(A, T, C, G\) 的字符串,且满足不出现指定的一些字符串,问长度为 \(n\) 的字符串有多少种 ? 分析 AC 自动机 + 矩阵快速幂的神题 ,知识点很 ...

  10. 18、Flask实战第18天:Flask-session

    session的基本概念 session和cookie的作用有点类似,都是为了存储用户相关的信息.不同的是,cookie是存储在本地浏览器,session是一个思路.一个概念.一个服务器存储授权信息的 ...