高级程序设计.doc_第1页
高级程序设计.doc_第2页
高级程序设计.doc_第3页
高级程序设计.doc_第4页
高级程序设计.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

高级程序设计实验报告实 验 报 告专业_信息与计算科学 班级 _姓名_马晨晨_ _学号 2011326630218 _课程名称windows程序设计_学年 2014 学期 1 / 2 课程类别 专业必修 限选 任选实践l 实验内容: 网络通信程序实验:服务器 l 实验时间: 2014年6月 l 实验目的及要求:目的:检验学习成果,增强实践能力要求:按时完成,并上交实验报告l 实验内容、方法与步骤: 一、 服务器管理界面,实现服务器的启动和停止二、 用户信息管理1.用户信息存贮在文件中,预先存储每一个用户的通信号、昵称。存储格式自定。三 、通信协议定义和服务器端实现:协议1.用户登录,由客户端向服务器端发送:L|通信号|昵称|在线状态其中在线状态包括”在线”和”隐身”两种协议2. 用户登录反馈,由服务器向客户端发送P|登录是否成功|好友列表其中登录是否成功用“OK”|“ERROR”表示好友列表为:通信号1,昵称1;通信号2,昵称2即好友之间用 “;”分割,结尾没有“;”,一个好友由通信号和昵称两部分组成,用”,”分割协议3. 好友状态反馈,服务器向客户端反馈当某个客户端向服务器发送登录信息,且登录信息中在线状态为在线时,服务器端需要向其所有好友客户端发送客户状态,发送格式如下:Q|通信号|昵称|在线状态 当某个客户端向服务器发送退出信息时,情况类似。协议4. 好友发送信息,客户端向服务端发送 当某个客户端想向另外一个客户端发送信息时候,发送客户端将信息发送到服务器端。发送格式如下:C|自己的通信号|对方通信号|信息正文协议5. 服务器转发信息,服务器向客户端发送 当服务器收到某个客户端向另外一个客户端发送信息时候,将向目标客户端转发。发送格式如下:C|发送方通信号|接收端通信号|信息正文协议6. 退出登录,客户端向服务器发送当客户端程序退出前,向服务器端发送E|发送方通信号l 实验结果:俩个主窗体:Form1Form2源代码:Form1:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Xml;using Microsoft.Win32;using System.IO;using qqServerManger;namespace qqServer public partial class Form1 : Form private string SerIp = ; private string SerPort = ; private Server QQserver = new Server(); private string SysInf = QQ2008服务已经停止!; public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (boBox1.Text = ) MessageBox.Show(请选择服务器!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); else this.toolStripStatusLabel2.Text = 服务启动中; if (QQserver.IniServer(SerIp, SerPort) QQserver.StartServer(); XmlFileOp.DelThisFile(onlineinfonLine.xml); this.pictureBox1.Image = global:qqServer.Properties.Resources.start; this.button1.Enabled = false; this.button2.Enabled = true; SysInf = QQ2008服务正在运行!; this.notifyIcon1.Icon = (System.Drawing.Icon)(global:qqServer.Properties.Resources.ser_start); this.toolStripStatusLabel2.Text = 服务已经运行; else MessageBox.Show(无法初始化服务!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); private void button3_Click(object sender, EventArgs e) Form2 show = new Form2(); show.ShowDialog(); private void button2_Click(object sender, EventArgs e) if (QQserver.StopServer() this.button1.Enabled = true; this.button2.Enabled = false; this.toolStripStatusLabel2.Text = 服务已停止!; SysInf = QQ2008服务已经停止!; this.notifyIcon1.Icon = (System.Drawing.Icon)(global:qqServer.Properties.Resources.ser_stop); this.pictureBox1.Image = global:qqServer.Properties.Resources.stop; private void Form1_Load(object sender, EventArgs e) string SerXmlUrl=configipConfig.dat; SerIp = qSaveConfigServer.GetValueByNode(SerXmlUrl, /root/server/ip); SerPort = qSaveConfigServer.GetValueByNode(SerXmlUrl, /root/server/port); if (SerIp = -1 | SerPort = -1) MessageBox.Show(系统配置文件错误, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); this.button1.Enabled = false; else boBox1.Items.Add(SerIp); this.pictureBox1.Image = global:qqServer.Properties.Resources.stop; this.toolStripStatusLabel2.Text = 服务已停止!; this.button2.Enabled = false; private void checkBox1_CheckedChanged(object sender, EventArgs e) try if (this.checkBox1.Checked) RegistryKey ms_run = Registry.LocalMachine.OpenSubKey(SOFTWAREMicrosoftWindowsCurrentVersionRun, true); ms_run.SetValue(mistysoft, Application.ExecutablePath.ToString(); else RegistryKey ms_run = Registry.LocalMachine.OpenSubKey(SOFTWAREMicrosoftWindowsCurrentVersionRun, true); ms_run.SetValue(mistysoft, ); MessageBox.Show(保存成功!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); catch MessageBox.Show(保存设置失败!请确认本程序能够访问注册表, 失败, MessageBoxButtons.OK, MessageBoxIcon.Error); private void 退?出?ToolStripMenuItem_Click(object sender, EventArgs e) Application.Exit(); private void 关?于ToolStripMenuItem_Click(object sender, EventArgs e) Form3 fo = new Form3(); fo.ShowDialog(); private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) this.Visible = true; private void notifyIcon1_MouseMove(object sender, MouseEventArgs e) this.notifyIcon1.Text = SysInf; private void button4_Click(object sender, EventArgs e) Application.Exit(); Form2:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using qqServerManger;namespace qqServer public partial class Form2 : Form public Form2() InitializeComponent(); private void button3_Click(object sender, EventArgs e) this.Close(); private void button4_Click(object sender, EventArgs e) this.Close(); private void button1_Click(object sender, EventArgs e) if (regx.isNull(this.tIpQQ.Text) | regx.isNull(this.tPortQQ.Text) MessageBox.Show(请输入qq服务器ip地址或端口号, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); else if (regx.isIpaddres(this.tIpQQ.Text) if (qSaveConfigServer.SaveConfigServer(this.tIpQQ.Text, this.tPortQQ.Text) MessageBox.Show(信息保存成功!, 恭喜, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(保存失败!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show(你输入ip地址错误!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); private void button2_Click(object sender, EventArgs e) string DataIp = this.tDataIp.Text; string DataBase = this.tDataName.Text; string DataUid = this.tDataUid.Text; string DataPwd = this.tDataPwd.Text; if (regx.isNull(DataIp) | regx.isNull(DataBase) | regx.isNull(DataUid) | regx.isNull(DataPwd) MessageBox.Show(请你输入服务器信息!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); else if (regx.isIpaddres(DataIp) if (qSaveConfigServer.SaveConfigDate(DataIp, DataBase, DataUid, DataPwd) MessageBox.Show(信息保存成功!, 恭喜, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(保存失败!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show(你输入ip地址错误!, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error); private void but

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论