登陆界面:

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. PAT (Advanced Level) 1026. Table Tennis (30)

    情况比较多的模拟题. 交了50发的样子才AC......AC之后我的天空星星都亮了. #include<iostream> #include<cstring> #include ...

  2. OpenCV学习(20) grabcut分割算法

    http://www.cnblogs.com/mikewolf2002/p/3330390.html OpenCV学习(20) grabcut分割算法 在OpenCV中,实现了grabcut分割算法, ...

  3. mysql的数据类型int、bigint、smallint 和 tinyint取值范围

    使用整数数据的精确数字数据类型.   bigint   从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字 ...

  4. 解决在某些IE浏览器下字符乱码的问题

    习惯上我们写字符声明都是 <meta charset="utf-8"> 在绝大多数浏览器都没有问题,但是在操蛋的IE上有时候会出现编码错误!! 解决方案: <me ...

  5. tableView滑动到底部

    - (void)scrollToBottom { NSInteger sectionCount = [self.dataSource numberOfSectionsInTableView:self] ...

  6. css颜色渐变在不同浏览器的设置

    在web开发中,难免会遇到浏览器之间的兼容问题,关于Css设置颜色渐变下面有解决的办法,直接上代码: 适用于谷歌浏览器: background: -webkit-gradient(linear, 0 ...

  7. 利用OpenSSL创建证书链并应用于IIS7

    一.系统环境说明 Linux & OpenSSL Linux localhost -.el5 # SMP Tue Mar :: EDT x86_64 x86_64 x86_64 GNU/Lin ...

  8. Delphi 内存分配 StrAlloc New(转)

    源:Delphi 内存分配 StrAlloc New 引自:http://anony3721.blog.163.com/blog/static/5119742010824934164/   给字符指针 ...

  9. js实现的文章输入检查与测速。(纯js版本)

    朋友又提出一些需求.希望不要jquery .于是修改成js版本. <!DOCTYPE html> <html> <head> <meta charset=&q ...

  10. linux  指令 备注

    ss命令可用于查看系统的socket的状态.基本上ss是比较符合需求的ss -a 出来的答案比较完整,但是很乱...连dgram及stream都分开了ss -l 比较可能是需要的,这会列出所有正在使用 ...