首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 数据库 第二书店 程序员

C#通讯编程(整理)|大家可以进来学习


koobee学生在校写的《银证转帐系统》的通信代码

C# code
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace SERVERsocket
{
class SERVER
{
private Thread serverThread;
private Thread recvThread;
private TcpListener tcpListener;
private NetworkStream networkStream;
private StreamReader streamReader;
private StreamWriter streamWriter;
private Socket socketForClient;
private string message;
private int operatorNO;
private bool[] isOperated;

private void Listen()
{
try
{
Int32 port = Int32.Parse("2020");
IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
tcpListener = new TcpListener(IPAddress.Any, port);
//开始侦听
tcpListener.Start();
//返回可以用以处理连接的Socket实例
socketForClient = tcpListener.AcceptSocket();
if (socketForClient.Connected)
{
networkStream = new NetworkStream(socketForClient);
streamReader = new StreamReader(networkStream);
streamWriter = new StreamWriter(networkStream);
recvThread = new Thread(new ThreadStart(RecvData));
recvThread.Start();
}
MessageBox.Show("客户端成功连接上服务器!");
}

catch (Exception exc)
{
MessageBox.Show(exc.Message, "Server提示");
}
}

//接收数据
private void RecvData()
{
string msg = streamReader.ReadLine();
string[] tokens = msg.Split(new char[] { '#' });
//MessageBox.Show(tokens[0]);
//MessageBox.Show(tokens[1]);
//MessageBox.Show(tokens[2]);

while (!msg.Equals("clientExit"))
{
switch (tokens[0])
{
case "c01":
{
//MessageBox.Show("开始登陆!");
//下面写SQL语句,查询对应的帐户密码是否正确,并返回信息
SqlConnection thisConnection = new SqlConnection("server = localhost;Integrated Security =true;database = security");
SqlCommand comn = new SqlCommand("select 密码 from 帐户表 where 账号=" + tokens[1], thisConnection);
thisConnection.Open();
SqlDataAdapter thisAdapt = new SqlDataAdapter("select * from 帐户表", thisConnection);
DataSet thisDataSet = new DataSet();
thisAdapt.Fill(thisDataSet, "帐户表");
string s = comn.ExecuteScalar().ToString();


// MessageBox.Show(s);
// MessageBox.Show(tokens[2]);


if (s.CompareTo(tokens[2]) == 0)
{
streamWriter.Write("1");
streamWriter.Flush();
tokens[0].Remove(0);
// MessageBox.Show("登陆消息已发送");
}
else
{
streamWriter.Write("1");
streamWriter.Flush();
tokens[0].Remove(0);
// MessageBox.Show("登陆");
}

}
break;


case "c02":
{
//下面写SQL语句,查询对应账户的余额,并返回信息
SqlConnection thisConnection = new SqlConnection("server = localhost;Integrated Security =true;database = security;");
SqlDataAdapter thisAdapt = new SqlDataAdapter("select * from 帐户表", thisConnection);
SqlCommandBuilder thisbuider = new SqlCommandBuilder(thisAdapt);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisConnection.Open();
DataSet thisDataSet = new DataSet();
thisAdapt.Fill(thisDataSet, "帐户表");
string s1 = "select 金额 from 帐户表 where 账号=" + tokens[1];
setMessage("c002#" + s1); //填写账户余额
SendData();
tokens[0].Remove(0);
}
break;
case "c03":
{
//更改帐户密码的sql语句,完成后返回数据003成功
SqlConnection thisConnection = new SqlConnection("server = localhost;Integrated Security =true;database = security;");
SqlDataAdapter thisAdapt = new SqlDataAdapter("select * from 帐户表", thisConnection);
SqlCommandBuilder thisbuider = new SqlCommandBuilder(thisAdapt);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisConnection.Open();
DataSet thisDataSet = new DataSet();
thisAdapt.Fill(thisDataSet, "帐户表");
foreach (DataRow rows in thisDataSet.Tables["帐户表"].Rows)
{

string s1 = "select 密码 from 帐户表 where 账号=" + tokens[1];
if (s1.CompareTo(tokens[1]) == 0)
{
thisCommand.CommandText = "update 帐户表 set 密码 = " + tokens[3] + "where 账号=" + tokens[1];
setMessage("c003#1"); //修改密码成功
SendData();
tokens[0].Remove(0);
}
else
{
setMessage("c003#2"); //修改密码失败
SendData();
tokens[0].Remove(0);
}
}
}
break;





他们设置了哪些标签:


.net 1 2 3 C# C#_C#通讯编程(整理) C#通讯 C#通讯编程 C#通讯编程(代码) C#通讯编程(整理 C#通讯编程(整理) C#通讯编程(整理)| C#通讯编程(整理)|大家可以进来学习 C#通讯编程资料 C#网络 c#网络编程 C#学习 http://topic.csdn.net/u/20080623/08/4bbd2475-45f1-42e3-a613-16b094759ade.html SOCKET socket通讯 Stocket编程 TCP tongxun tongxunbiancheng UDP 多线程 技术相关 论坛C# 通信 通讯 通讯编程 网络 学习 异步模式

谁收藏了这个网址:


fuda_1985收录

时间:2008-6-23 8:38:24 | 相关网摘

starlessnt收录

时间:2008-6-23 8:54:49 | 相关网摘

tiancs收录

时间:2008-6-23 9:14:03 | 相关网摘

ffanpeng收录

时间:2008-6-23 10:16:17 | 相关网摘

ltb55232133收录

时间:2008-6-23 10:29:05 | 相关网摘

alang0610收录

时间:2008-6-23 10:53:38 | 相关网摘

slight43收录

时间:2008-6-23 11:02:05 | 相关网摘

along7599收录

时间:2008-6-23 11:32:06 | 相关网摘

viki117收录

时间:2008-6-23 11:40:58 | 相关网摘

vchao13收录

时间:2008-6-23 11:47:11 | 相关网摘

netfeel2008收录

使用标签:C#通讯,时间:2008-6-23 12:00:19 | 相关网摘

zanfeng收录

时间:2008-6-23 12:38:40 | 相关网摘

lawrendc收录

时间:2008-6-23 13:47:03 | 相关网摘

JustLovePro收录

时间:2008-6-23 13:59:11 | 相关网摘

zhouzhou830930收录

时间:2008-6-23 14:38:43 | 相关网摘

Thread signal.线程 用一个指示是否将初始状态设置为终止的布尔值初始化 ManualResetEvent 类的新实例。
public static ManualResetEvent allDone = new ManualResetEvent(false);
//static void Main(string[] args)

gxj760998收录

时间:2008-6-23 15:03:48 | 相关网摘

harryhdk收录

使用标签:C#通讯,时间:2008-6-23 15:28:46 | 相关网摘

tu1101收录

时间:2008-6-23 15:49:18 | 相关网摘

Magichi收录

时间:2008-6-23 16:00:44 | 相关网摘

fifastar收录

时间:2008-6-23 16:06:46 | 相关网摘

zerolimb收录

时间:2008-6-23 16:31:05 | 相关网摘

jrl5365收录

使用标签:C#通讯编程,时间:2008-6-23 16:46:39 | 相关网摘

fancystyle收录

时间:2008-6-23 16:47:12 | 相关网摘

zhanght0102收录

时间:2008-6-23 16:58:56 | 相关网摘

kenny8023收录

时间:2008-6-23 17:19:42 | 相关网摘

chensiboy收录

时间:2008-6-23 18:16:12 | 相关网摘

ruoyanzhang收录

时间:2008-6-23 18:33:16 | 相关网摘

sock

mfineky收录

时间:2008-6-23 20:24:39 | 相关网摘

shutonga收录

时间:2008-6-23 21:22:11 | 相关网摘

liusiyang收录

时间:2008-6-23 22:22:38 | 相关网摘

changgongyexia收录

时间:2008-6-23 22:57:48 | 相关网摘

maniunet收录

时间:2008-6-24 0:03:36 | 相关网摘

yaazz收录

使用标签:通讯,时间:2008-6-24 8:17:46 | 相关网摘

fenghao_5555收录

时间:2008-6-24 8:32:52 | 相关网摘

xzf158收录

时间:2008-6-24 8:35:22 | 相关网摘

kevinlui2008收录

时间:2008-6-24 8:52:56 | 相关网摘

SSXYC收录

时间:2008-6-24 8:56:25 | 相关网摘

wang02收录

时间:2008-6-24 9:04:20 | 相关网摘

C#通讯编程(整理)|大家可以进来学习

kylewell收录

时间:2008-6-24 9:16:20 | 相关网摘

kulouto收录

时间:2008-6-24 9:23:19 | 相关网摘

lhh19879收录

时间:2008-6-24 9:44:58 | 相关网摘

kangbinoopp收录

时间:2008-6-24 10:00:54 | 相关网摘

wanghousheng收录

使用标签:C#通讯编程(整理),时间:2008-6-24 11:15:39 | 相关网摘

C#通讯编程(整理)

my145794收录

时间:2008-6-24 11:17:37 | 相关网摘

bigfoot001收录

时间:2008-6-24 11:34:57 | 相关网摘

lr21shiji收录

时间:2008-6-24 11:56:39 | 相关网摘

airport0928收录

时间:2008-6-24 11:58:27 | 相关网摘

C#通讯编程

mengxj85收录

使用标签:C#通讯编程(整理)|大家可以进来学习,时间:2008-6-24 11:59:32 | 相关网摘

C#通讯编程(整理)|大家可以进来学习

xian_china收录

时间:2008-6-24 12:59:00 | 相关网摘

lrt0626收录

时间:2008-6-24 13:15:16 | 相关网摘

arming432收录

使用标签:C#通讯编程,时间:2008-6-24 13:26:01 | 相关网摘

C#通讯编程

gwqwyh收录

使用标签:C#通讯编程(整理,时间:2008-6-24 15:03:39 | 相关网摘

ys_w收录

时间:2008-6-24 15:41:05 | 相关网摘

chinazjf收录

时间:2008-6-24 16:17:03 | 相关网摘

konta收录

时间:2008-6-24 16:24:12 | 相关网摘

xujiaoxiang收录

时间:2008-6-24 16:30:13 | 相关网摘

jankercsdn收录

时间:2008-6-24 17:04:39 | 相关网摘

sunyante8收录

时间:2008-6-24 17:21:33 | 相关网摘

s000rd收录

时间:2008-6-24 17:22:08 | 相关网摘

popule_daisy收录

时间:2008-6-24 17:27:25 | 相关网摘

zeallag1收录

时间:2008-6-24 18:15:15 | 相关网摘

pengzhanchi82收录

时间:2008-6-24 19:12:55 | 相关网摘

reacle收录

时间:2008-6-24 19:21:14 | 相关网摘

51Crack收录

时间:2008-6-24 21:02:16 | 相关网摘

gh_li收录

时间:2008-6-24 21:11:21 | 相关网摘

pingzilu收录

使用标签:C#通讯编程,时间:2008-6-25 1:39:46 | 相关网摘

WO_YOU_XIE_SHANG_XIN收录

时间:2008-6-25 8:49:53 | 相关网摘

lizeqin503收录

时间:2008-6-25 9:16:18 | 相关网摘

emenwin收录

时间:2008-6-25 10:05:16 | 相关网摘

xiaogang107收录

时间:2008-6-25 10:13:08 | 相关网摘

C#通讯编程

chengqscjh收录

时间:2008-6-25 10:14:33 | 相关网摘

mackencap收录

时间:2008-6-25 10:37:06 | 相关网摘

hillspring收录

时间:2008-6-25 10:42:13 | 相关网摘

daone收录

使用标签:Stocket编程,时间:2008-6-25 10:51:27 | 相关网摘

C#通信的DEMO

Justin1818收录

时间:2008-6-25 11:01:52 | 相关网摘

etherealkite收录

时间:2008-6-25 11:30:37 | 相关网摘

huzhijia收录

时间:2008-6-25 11:34:00 | 相关网摘

linnyn收录

时间:2008-6-25 11:42:07 | 相关网摘

C#通讯编程

lylinsir2008收录

时间:2008-6-25 11:53:46 | 相关网摘

skyming521收录

时间:2008-6-25 12:25:30 | 相关网摘

slin60收录

时间:2008-6-25 12:28:57 | 相关网摘

Valetta收录

时间:2008-6-25 12:43:26 | 相关网摘

ASCII

paulyjin收录

时间:2008-6-25 12:44:53 | 相关网摘

yxb0317收录

时间:2008-6-25 14:52:13 | 相关网摘

softheaded收录

时间:2008-6-25 15:42:17 | 相关网摘

ojlovecd收录

时间:2008-6-25 15:54:56 | 相关网摘

maomao648048803收录

使用标签:3,时间:2008-6-25 16:30:50 | 相关网摘

wubaojie收录

时间:2008-6-25 17:17:32 | 相关网摘

luosjz收录

时间:2008-6-25 17:31:41 | 相关网摘

xy_wolf收录

时间:2008-6-25 17:33:24 | 相关网摘

hang51收录

时间:2008-6-25 17:52:30 | 相关网摘

flyingdream123收录

时间:2008-6-25 19:36:07 | 相关网摘

minyskirt收录

时间:2008-6-25 21:18:05 | 相关网摘

lc7cl收录

时间:2008-6-25 21:28:15 | 相关网摘

kyle315收录

时间:2008-6-25 22:08:00 | 相关网摘

banAlist收录

时间:2008-6-26 2:10:38 | 相关网摘

eagle9363收录

时间:2008-6-26 8:37:15 | 相关网摘

symbol441收录

时间:2008-6-26 9:25:23 | 相关网摘

wanbolantian收录

时间:2008-6-26 9:29:49 | 相关网摘

iew_study收录

时间:2008-6-26 9:30:32 | 相关网摘


网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
Copyright © 2000-2008, CSDN.NET, All Rights Reserved