关于我的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的蓝牙聊天软件,目前仅 ...
随机推荐
- Highcharts一些属性
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- background系列属性
1.background-color背景颜色属性 ①颜色表示方法 英语单词:red blue purple skyblue. rgb:r代表红色 g代表绿色 b代表蓝色 也 ...
- C语言常见命名规范
C语言常见命名规范 1 常见命名规则 比较著名的命名规则首推匈牙利命名法,这种命名方法是由Microsoft程序员查尔斯·西蒙尼(Charles Simonyi) 提出的.其主要思想是“在变量和函 ...
- R语言相关工具
R: 下载 R语言的基础工具,包括R编译器,R控制台等 RStudio:下载 R程序集成开发环境.特别好用,包括一系列的集成工具. Rtools:下载 Windows环境下,编译R包的工具库.也可以用 ...
- OPENCV图像特征点检测与FAST检测算法
前面描述角点检测的时候说到,角点其实也是一种图像特征点,对于一张图像来说,特征点分为三种形式包括边缘,焦点和斑点,在OPENCV中,加上角点检测,总共提供了以下的图像特征点检测方法 FAST SURF ...
- Delphi中unicode转汉字函数(转)
源:Delphi中unicode转汉字函数 近期用到这个函数,无奈没有找到 delphi 自带的,网上找了下 有类似的,没有现成的,我需要的是 支持 “\u4f00 ” 这种格式的,即前面带标准的 “ ...
- HDU 5650 so easy
n不为1的时候输出a[1],否则输出0 #include<cstdio> #include<cstring> #include<cmath> #include< ...
- 9、手把手教你Extjs5(九)使用MVVM特性控制菜单样式
菜单的样式多了,怎么可以灵活的切换是个问题. 在使用标准菜单的时候,在菜单最前面有二个按钮,可以切换到树状菜单和按钮菜单. 在树状菜单的显示区,可以切换换到标准菜单,以及折叠式菜单. 切换到按钮菜单之 ...
- FMDB的一些基本操作小结
http://blog.csdn.net/iunion/article/details/7204625 仅供自己记录使用, h文件 #import <Foundation/Foundation. ...
- 对AD域进行定期自动备份设置图解
今天为大家讲解一下,如何对域进行定期的备份,因为如果域出问题了,在公司里那可就不好玩了啊,对做定期备份,在域出问题的时候可以及时恢复,减少对域重建而浪费大量的时间,同样也耽误公司员工的工作,这样的事情 ...