关于我的PP0.1聊天软件(客户端)
登陆界面:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml; namespace PP0._1
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
public static String ip;
public static int port;
bool formMove = false;//窗体是否移动
Point formPoint;//记录窗体的位置
private void Login_Load(object sender, EventArgs e)
{
initServiseInfo();
}
public void initServiseInfo()
{
XmlDocument doc = new XmlDocument();
doc.Load("ServiseInfo.xml");
XmlNode root = doc.DocumentElement;
foreach(XmlNode item in root.ChildNodes){
switch (item.Name)
{
case "ip":
ip = item.InnerText;
break;
case "port":
port = Convert.ToInt32(item.InnerText);
break;
}
}
} private void btnLogin_Click(object sender, EventArgs e)
{
LoginNow();
}
public void LoginNow()
{
if (txtName.Text!="" && txtPwd.Text!="")
{
byte[] byteOrder = new byte[1024];
String userInfo = "name:" + txtName.Text + "pwd:" + txtPwd.Text + "type:1";//1为登陆
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
socket.Send(Encoding.ASCII.GetBytes(userInfo));
String order = Encoding.ASCII.GetString(byteOrder, 0, socket.Receive(byteOrder));
if (order == "loginSucceed")
{
this.Hide();
PPMian main = new PPMian();
main.Show();
}
else if (order == "noUser")
{
DialogResult result = MessageBox.Show("未存在此用户,是否跳转,注册页面?", "", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.Hide();
Register register = new Register();
register.Show();
}
}
else if (order=="pwdErro")
{
MessageBox.Show("密码错误");
}
}
else if (txtName.Text=="")
{
MessageBox.Show("用户名不能为空");
}
else if (txtPwd.Text=="")
{
MessageBox.Show("密码不能为空");
} } private void linkLabRegister_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Register register = new Register();
register.Show();
this.Hide();
} private void labLogin_Click(object sender, EventArgs e)
{ } private void pictureBox1_Click(object sender, EventArgs e)
{ } private void Login_MouseDown(object sender, MouseEventArgs e)
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
} private void Login_MouseMove(object sender, MouseEventArgs e)
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
} private void Login_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
} private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
} private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
} private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
} private void btnExit_Click(object sender, EventArgs e)
{
DialogResult result= MessageBox.Show("是否确定退出?","",MessageBoxButtons.YesNo);
if (result==DialogResult.Yes)
{
System.Environment.Exit(0);
}
}
}
}
读取xml文件,获取ip和端口
public void initServiseInfo()
{
XmlDocument doc = new XmlDocument();
doc.Load("ServiseInfo.xml");
XmlNode root = doc.DocumentElement;
foreach(XmlNode item in root.ChildNodes){
switch (item.Name)
{
case "ip":
ip = item.InnerText;
break;
case "port":
port = Convert.ToInt32(item.InnerText);
break;
}
}
}
登陆的判断操作
public void LoginNow()
{
if (txtName.Text!="" && txtPwd.Text!="")
{
byte[] byteOrder = new byte[1024];
String userInfo = "name:" + txtName.Text + "pwd:" + txtPwd.Text + "type:1";//1为登陆
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
socket.Send(Encoding.ASCII.GetBytes(userInfo));
String order = Encoding.ASCII.GetString(byteOrder, 0, socket.Receive(byteOrder));
if (order == "loginSucceed")
{
this.Hide();
PPMian main = new PPMian();
main.Show();
}
else if (order == "noUser")
{
DialogResult result = MessageBox.Show("未存在此用户,是否跳转,注册页面?", "", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.Hide();
Register register = new Register();
register.Show();
}
}
else if (order=="pwdErro")
{
MessageBox.Show("密码错误");
}
}
else if (txtName.Text=="")
{
MessageBox.Show("用户名不能为空");
}
else if (txtPwd.Text=="")
{
MessageBox.Show("密码不能为空");
}
}
注册界面:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; namespace PP0._1
{
public partial class Register : Form
{
public Register()
{
InitializeComponent();
}
bool formMove = false;//窗体是否移动
Point formPoint;//记录窗体的位置
private void Register_MouseDown(object sender, MouseEventArgs e)
{
formPoint = new Point();
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
formPoint = new Point(xOffset, yOffset);
formMove = true;//开始移动
}
} private void Register_MouseMove(object sender, MouseEventArgs e)
{
if (formMove == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(formPoint.X, formPoint.Y);
Location = mousePos;
}
} private void Register_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
formMove = false;//停止移动
}
} private void btnCancle_Click(object sender, EventArgs e)
{
this.Hide();
Login login = new Login();
login.Show();
} private void btnRegister_Click(object sender, EventArgs e)
{
RegisterNow();
}
public void RegisterNow()
{
if (txtName.Text!="" && txtPwd.Text!="")
{
byte[] byteOrder=new byte[1024];
String userInfo = "name:" + txtName.Text + "pwd" + txtPwd.Text+"type:2";//2为注册
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(IPAddress.Parse(Login.ip), Login.port));
socket.Send(Encoding.ASCII.GetBytes(userInfo));
String order;
order = Encoding.ASCII.GetString(byteOrder,0,socket.Receive(byteOrder));
if (order == "registerSucceed")
{
MessageBox.Show("注册成功");
Login login = new Login();
this.Hide();
login.Show();
}
else if (order=="userLess")
{
MessageBox.Show("用户名重名,请重新注册");
}
}else if(txtName.Text==""){
MessageBox.Show("用户名不能为空");
}
else if (txtPwd.Text=="")
{
MessageBox.Show("密码不能为空");
} }
private void Register_Load(object sender, EventArgs e)
{ }
}
}
关于我的PP0.1聊天软件(客户端)的更多相关文章
- Android 聊天软件客户端
1.代码架构图 2.qq.model层 3.qq.app层 4.qq.Constatnt层 5.qq.util层 6.qq.broadcast层 7.qq.control层 8.qq.view层 9. ...
- Java实现 简单聊天软件
简单的聊天软件 //客户端 package yjd9; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...
- 用Delphi开发视频聊天软件
摘要:目前网上视频聊天软件.视频会议软件.可视IP电话软件随处可见,你是否想自己做一个玩玩?其实这类软件无非是视频加上网络而建成的.如果熟悉视频捕捉和网络传输技术,根本就难不倒你.微软为软件开发人员提 ...
- 43.QQ聊天软件GUI窗口编写
QQ聊天软件代码功能编写 一,Tkinter聊天界面编写 1,聊天软件客户端界面开发-1 Tkinter的模块(“TK接口”)是标准的Python接口从Tk的GUI工具包 https://i.cnbl ...
- 局域网聊天软件(winsocket)
LANChat工作整理 2013/8/22 程序实现功能: 局域网聊天软件,启动即可找到在线设备,并能够进行简单的文字聊天. 其实下面这个框图已经说明了程序的绝大部分功能原理. 核心类的程序框图 我觉 ...
- 【Python网络编程】多线程聊天软件程序
课程设计的时候制作的多线程聊天软件程序 基于python3.4.3 import socket import pickle import threading import tkinter import ...
- python练习四—简单的聊天软件
python最强大的是什么?库支持!!有了强大的库支持,一个简单的聊天软件实现就更简单了,本项目思路如下 # 项目思路 1. 服务器的工作 * 初始化服务器 * 新建一个聊天房间 * 维护一个已链接用 ...
- Linux 下 c 语言 聊天软件
这是我学C语言写的第一个软件,是一个完整的聊天软件,里面包括客户端,和服务器端,可以互现聊天,共享文件,有聊天室等,是一个有TCP和UDP协议的聊天软件,测试过很多次在CENTOS和UBUNTU下都通 ...
- 基于Android Classic Bluetooth的蓝牙聊天软件
代码地址如下:http://www.demodashi.com/demo/12133.html BluetoothChat 基于Android Classic Bluetooth的蓝牙聊天软件,目前仅 ...
随机推荐
- background系列属性
1.background-color背景颜色属性 ①颜色表示方法 英语单词:red blue purple skyblue. rgb:r代表红色 g代表绿色 b代表蓝色 也 ...
- PHP json不转义
json_encode($result, JSON_UNESCAPED_UNICODE);
- C++------------typedef 函数指针类型定义
摘要bycrazyhacking: typedef 是定义了一种"函数指针"类型,可以再声明很多变量.函数指针的定义是定义了一个变量. int max(int x,i ...
- pymongo一次更新多条数据
db.collection.update(query, update, upsert, multi) pymongo使用示例 db.collection.update({}, {'$set' : {' ...
- VS2010与SVN
http://blog.sina.com.cn/s/blog_4fe44775010182yl.html 在VS2010中使用SVN,必须先安装SVN的客户端,再安装VisualSVN(SVN的插件) ...
- jquery toggle 替换的实现
$('#example').click(function(){$("#exampleBox").toggle();}) 改为 $('#example').click(functio ...
- POJ3723最小生成树
题意:从一个起点出发连接男孩子和女孩子,若是两者之间有连接的,则花费为10000-d,若是没有连接的则花费为10000 分析:很显然是一个最小生成树,但是我们希望的是d越大越好,因为d越大,10000 ...
- jQuery.extend({...})分析
作者:zccst 看一下是如何写的 jQuery.extend({ prop:"" method:function(){} }); 可以看出,这些方法是jQuery的静态属性和方法 ...
- Kmeans在MapReduce中的实现
参考了http://www.cnblogs.com/chaoku/p/3748456.html?utm_source=tuicool的代码.不过他的代码细节上有点问题.主要在于对于质心的处理上,他的代 ...
- POJ 3458 Colour Sequence
水题. #include<cstdio> #include<cstring> #include<cmath> + ; char s[maxn], v[maxn], ...