资源简介
基于客户-服务模式的局域网简易抢答器,用C#+VS2005编写
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Threading;
using System.Net;
namespace QuickAnswerClient
{
public partial class Answer : Form
{
private string userName;
private IPAddress serverIP;
private IPAddress clientIP;
private int serverPort;
private IPEndPoint myServer;
private Socket connectSocket;
private Thread receiveThread = null;
private const int _maxPacket = 64 * 1024;
private bool flagFirstHit;
#region 发送的消息
byte[] msgUsername;
byte[] msgQuit = System.Text.Encoding.Unicode.GetBytes(“quit“);
#endregion
public Answer(string user IPAddress ip int portSocket skt)
{
InitializeComponent();
userName = user;
serverIP = ip;
connectSocket = skt;
serverPort = port;
myServer = new IPEndPoint(serverIP serverPort);
clientIP = Dns.GetHostAddresses(Dns.GetHostName())[0];
lbLocalIP.Text = “本地IP:“ + clientIP;
lbUsername.Text = “用户名:“ + userName;
lbServerIP.Text = “服务器IP:“ + serverIP;
msgUsername = System.Text.Encoding.Unicode.GetBytes(userName);
flagFirstHit = true;
receiveThread = new Thread(new ThreadStart(begReceive));
receiveThread.Start();
}
#region 其他线程修改窗体控件
private void ChangebtnStartAnswer() //更新开始抢答按钮
{
btnStartAnswer.Enabled = true;
}
#endregion
private void begReceive()
{
while (true)
{
try
{
byte[] packetBuff = new byte[_maxPacket];
connectSocket.Receive(packetBuff);
string sContent = System.Text.Encoding.Unicode.GetString(packetBuff).Trim(‘\0‘);
if (sContent == “cmdStop“)
{
MessageBox.Show(“服务器中断请退出客户端“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
slbServerStatus.Text = “与服务器连接中断...“;
btnStartAnswer.Enabled = false;
return;
}
else if (sContent == “cmdReset“)
{
flagFirstHit = true;
MethodInvoker mi = new MethodInvoker(ChangebtnStartAnswer);
BeginInvoke(mi);
}
else if (sContent == “cmdSuccess“)
{
MessageBox.Show(“抢答成功“ “恭喜“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
}
else if (sContent == “cmdFail“)
{
MessageBox.Show(“抢答落后“ “遗憾“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
}
else if (sContent == “cmdFoul“)
{
MessageBox.Show(“抢答犯规 请等开始后再抢答“ “犯规“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
}
else
{
}
}
catch
{
if (receiveThread != null)
{
receiveThread.Abort();
}
connectSocket.Close();
break;
}
}
}
private void StartAnswer()
{
try
{
connectSocket.Send(msgUsername);
}
catch
{
MessageBox.Show(“请确认已连接服务器“ “提示“ MessageBoxButtons.OK MessageBoxIcon.Exclamation);
s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4264 2009-12-08 23:10 111\QuickAnswerClient\Answer.cs
文件 7013 2007-12-20 22:14 111\QuickAnswerClient\Answer.Designer.cs
文件 9674 2007-12-20 22:14 111\QuickAnswerClient\Answer.resx
文件 4262 2007-12-20 22:14 111\QuickAnswerClient\Backup\Answer.cs
文件 7013 2007-12-20 22:14 111\QuickAnswerClient\Backup\Answer.Designer.cs
文件 9674 2007-12-20 22:14 111\QuickAnswerClient\Backup\Answer.resx
文件 2216 2007-12-20 21:04 111\QuickAnswerClient\Backup\Login.cs
文件 5637 2007-12-20 21:04 111\QuickAnswerClient\Backup\Login.Designer.cs
文件 5814 2007-12-20 21:04 111\QuickAnswerClient\Backup\Login.resx
文件 2238 2007-12-17 23:09 111\QuickAnswerClient\Backup\mycom.ico
文件 398 2007-12-14 13:32 111\QuickAnswerClient\Backup\Program.cs
文件 1217 2007-12-17 20:06 111\QuickAnswerClient\Backup\Properties\AssemblyInfo.cs
文件 2541 2007-12-14 13:08 111\QuickAnswerClient\Backup\Properties\Resources.Designer.cs
文件 5612 2007-12-14 13:08 111\QuickAnswerClient\Backup\Properties\Resources.resx
文件 1023 2007-12-14 13:08 111\QuickAnswerClient\Backup\Properties\Settings.Designer.cs
文件 249 2007-12-14 13:08 111\QuickAnswerClient\Backup\Properties\Settings.settings
文件 3703 2007-12-18 15:04 111\QuickAnswerClient\Backup\QuickAnswerClient.csproj
文件 922 2007-12-14 16:20 111\QuickAnswerClient\Backup\QuickAnswerClient.sln
..A..H. 25088 2007-12-20 22:15 111\QuickAnswerClient\Backup\QuickAnswerClient.suo
文件 22016 2009-12-08 23:10 111\QuickAnswerClient\bin\Debug\QuickAnswerClient.exe
文件 46592 2009-12-08 23:10 111\QuickAnswerClient\bin\Debug\QuickAnswerClient.pdb
文件 5632 2005-12-08 14:51 111\QuickAnswerClient\bin\Debug\QuickAnswerClient.vshost.exe
文件 28672 2007-12-20 22:14 111\QuickAnswerClient\bin\Release\QuickAnswerClient.exe
文件 36352 2007-12-20 22:14 111\QuickAnswerClient\bin\Release\QuickAnswerClient.pdb
文件 14328 2009-12-08 21:18 111\QuickAnswerClient\bin\Release\QuickAnswerClient.vshost.exe
文件 490 2007-07-21 01:33 111\QuickAnswerClient\bin\Release\QuickAnswerClient.vshost.exe.manifest
文件 2216 2007-12-20 21:04 111\QuickAnswerClient\Login.cs
文件 5637 2007-12-20 21:04 111\QuickAnswerClient\Login.Designer.cs
文件 5814 2007-12-20 21:04 111\QuickAnswerClient\Login.resx
文件 2238 2007-12-17 23:09 111\QuickAnswerClient\mycom.ico
............此处省略143个文件信息
相关资源
- C#基于UDP的点对点语音聊天程序
- 基于UDP的文件传输DEMOC#编程实现,可
- UDP异步通讯SocketAsyncEventArgs
-
局域网聊天程序xm
l保存异步套接字 - 通过UDP将文件从服务器发送到客户端
- C#Socket 封装了Tcp/Udp传输字串、文件、
- P2P之UDP穿透NAT的原理与C#实现
- C#实现udp打洞客户端与服务器端源码
- c#udp文件传输
- C#.net udp 点对点聊天程序
- C#winform TCP通信 UDP通信 Socket通信 vs2
- C# SOCKET TCP UDP测试工具及源代码
- C# udp方式大文件传输
- C# UDP demo
- C# 类似treamviewer的远程桌面源码,使用
- C#超级通信调试工具
- C# Socket TCP和UDP报文及端口测试工具的
- C#下用UDP实现的文件传输
- C#服务端和客户端通信源码
- C#网络调试助手源码.rar
- c# UDP协议传送文件支持断点续传异步
- C# UDP 单点 广播 组播 最简单代码 适合
- UDP Messenger 1.0.unitypackage
- VB.NET UDP最全通信案例
- UDP server 控制台程序
- UDP c#的UDP通讯程序
- CSharp-QQdemo 基于 Udp协议
- CSharp-udp-tcp 使用C#实现TCP和UDP两种方式
- c# udp socket屏幕实时传输 .rar
- c#_udp_client_send_and_read
评论
共有 条评论