登陆界面:

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聊天软件(客户端)的更多相关文章

  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. ...

  2. Java实现 简单聊天软件

    简单的聊天软件 //客户端 package yjd9; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...

  3. 用Delphi开发视频聊天软件

    摘要:目前网上视频聊天软件.视频会议软件.可视IP电话软件随处可见,你是否想自己做一个玩玩?其实这类软件无非是视频加上网络而建成的.如果熟悉视频捕捉和网络传输技术,根本就难不倒你.微软为软件开发人员提 ...

  4. 43.QQ聊天软件GUI窗口编写

    QQ聊天软件代码功能编写 一,Tkinter聊天界面编写 1,聊天软件客户端界面开发-1 Tkinter的模块(“TK接口”)是标准的Python接口从Tk的GUI工具包 https://i.cnbl ...

  5. 局域网聊天软件(winsocket)

    LANChat工作整理 2013/8/22 程序实现功能: 局域网聊天软件,启动即可找到在线设备,并能够进行简单的文字聊天. 其实下面这个框图已经说明了程序的绝大部分功能原理. 核心类的程序框图 我觉 ...

  6. 【Python网络编程】多线程聊天软件程序

    课程设计的时候制作的多线程聊天软件程序 基于python3.4.3 import socket import pickle import threading import tkinter import ...

  7. python练习四—简单的聊天软件

    python最强大的是什么?库支持!!有了强大的库支持,一个简单的聊天软件实现就更简单了,本项目思路如下 # 项目思路 1. 服务器的工作 * 初始化服务器 * 新建一个聊天房间 * 维护一个已链接用 ...

  8. Linux 下 c 语言 聊天软件

    这是我学C语言写的第一个软件,是一个完整的聊天软件,里面包括客户端,和服务器端,可以互现聊天,共享文件,有聊天室等,是一个有TCP和UDP协议的聊天软件,测试过很多次在CENTOS和UBUNTU下都通 ...

  9. 基于Android Classic Bluetooth的蓝牙聊天软件

    代码地址如下:http://www.demodashi.com/demo/12133.html BluetoothChat 基于Android Classic Bluetooth的蓝牙聊天软件,目前仅 ...

随机推荐

  1. ajax跨域实现api 接口调用

    背景: 想实现跨域去调用接口, 然后同时支持下次调用,能够带cookie信息过来,同时支持来自多个源头的域名的跨域调用. 1.这样支持来自所有域名的跨域调用: 不支持跨域是,浏览器报错: 在api接口 ...

  2. hadoop hdfs uri详解

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  3. 搭建firefly服务端遇到的问题

    1 pylinter pylinter could not automatically determined the path to "lint.py" 这个错误通过安装pylin ...

  4. Application_Start和Application_End事件执行时间

    Application_start: 第一个访问网站的用户会触发该方法. 通常会在该方法里定义一些系统变量,如聊天室的在线总人数统计,历史访问人数统计的初始化等等均可在这里定义. Applicatio ...

  5. label中添加图片

    创建NSTextAttachment的对象,用来装在图片 将NSTextAttachment对象的image属性设置为想要使用的图片 设置NSTextAttachment对象bounds大小,也就是要 ...

  6. HTML学习(八)列表和块

    无序列表无序列表是一个项目的列表,此列项目使用粗体圆点(典型的小黑圆圈)进行标记.无序列表始于 <ul> 标签.每个列表项始于 <li>.<ul type=“”> ...

  7. IT技术网站汇总

    首先是比较著名的博客型的网站!一般来说在国外比较著名的博客基本上都是比较有影响力发起的或者建立的经常发布一些比较有思考力深入分析的文章! 博客媒体网站 1.www.ArsTechnica.com 2. ...

  8. IOS 股票K线图、分时图

    IOS 股票K线图.分时图,网上开源项目很少,质量也是参差不齐:偶尔搜索到看似有希望的文章,点进去,还是个标题党:深受毒害.经过一段时间的探索,终于在开源基础上完成了自己的股票K线图.分时图: 先放出 ...

  9. LearningDocker--Chapter3--Building images

    This chapter is quite different from the earlier ones, and it is in this chapter to clearly describe ...

  10. java 图片生成缩略图后,转化成流

    功能:图片生成缩略图后,转化成流 public class ImageUtils { /** * * @param in1 * 文件流 * @param uploadFileName * 文件名称 * ...