鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > .net技术 > winform编程 > >

网站具体开发流程

来源:互联网 作者:佚名 时间:2013-12-28 10:44
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.IO; 7 using System.Linq; 8 using System.Net; 9 using System.Net.Sockets; 10 using System.Runtime

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.IO; 7 using System.Linq; 8 using System.Net; 9 using System.Net.Sockets; 10 using System.Runtime.Serialization.Formatters.Binary; 11 using System.Text; 12 using System.Threading; 13 using System.Threading.Tasks; 14 using System.Windows.Forms; MyServer 17 { forMyServer : Form 19 { 20 public forMyServer() 21 { 22 InitializeComponent(); 23 } BinaryFormatter formatter = menuAdd_Click(object sender, EventArgs e) 27 { 28 forAddServer f = new forAddServer(); f.ShowDialog(); 31 } ServerSite(Site s) { 34 treeView1.Nodes.Clear(); 35 sites.Add(s); ;path = Application.ExecutablePath;path = path.Substring()); + fileName;(FileStream fs = new FileStream(fileName, FileMode.Create)) 41 { 42 formatter = new BinaryFormatter(); } ); 46 treeView1.Nodes.Add(root); { 49 TreeNode node = new TreeNode(site.SiteName); 50 node.Tag = site; 51 root.Nodes.Add(node); 52 } 53 } forMyServer_Load(object sender, EventArgs e) 56 { ; 58 string path = Application.ExecutablePath; )); + fileName; 61 sites = new Sites(); 62 if (!File.Exists(fileName)) 63 File.Create(fileName); 64 using (FileStream fs = new FileStream(fileName, FileMode.Open)) 65 { 66 if (sites != null) 67 { 68 formatter = new BinaryFormatter(); 69 sites = formatter.Deserialize(fs) as Sites; ); 71 treeView1.Nodes.Add(root); 72 foreach (Site s in sites) 73 { 74 TreeNode node = new TreeNode(s.SiteName); 75 node.Tag = s; 76 root.Nodes.Add(node); 77 } 78 } 79 } 80 } menuStart_Click(object sender, EventArgs e) 83 { (treeView1.SelectedNode != null && treeView1.SelectedNode.Level > 0) 86 { Site currSite = treeView1.SelectedNode.Tag as Site; (!currSite.IsStart) 91 { 92 ParameterizedThreadStart p = new ParameterizedThreadStart(ListenSocket); 93 Thread t1 = new Thread(p); } 96 } 97 } ListenSocket( { 100 Site s = currSite as Site; 101 Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 102 EndPoint endPoint = new IPEndPoint(IPAddress.Any, 8080); 103 server.Bind(endPoint); s.IsStart = HttpContext h = new HttpContext(); 107 h.SitePath = s.Path; 108 while(true) 109 { h.TxSocket = client; 112 Thread t = new Thread(Process); 113 t.Start(h); 114 } 115 } Process( { 118 HttpContext h = c as HttpContext; 119 Socket client = h.TxSocket; [1024]; 121 int length = client.Receive(b); h.Info = h.Response = HttpAllContext allContext = h.Context = allContext; 127 HttpFactory.CreateHandler(h); client.Send(h.Response.b);client.Close(); } 退出服务ToolStripMenuItem_Click(object sender, EventArgs e) 134 { 135 Application.Exit(); 136 } 137 } 138 }

网友评论
<