⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otherclient.cs

📁 c#网络编程及应用-刘瑞新
💻 CS
字号:
using System;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace Game2D
{
	/// <summary>
	/// ThreadProcessor 的摘要说明。
	/// </summary>
	///
 
	public class OtherClient
	{

		private Socket client;
		private byte[] bb=new Byte[256];

		public OtherClient(Socket clientSocket)
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
			client=clientSocket;

			bb=System.Text.Encoding.BigEndianUnicode.GetBytes("Sorry");
			try
			{
				client.Send(bb,bb.Length,0);
			}
			catch
			{
				Initiator.richTextBox1.AppendText("error seading sorry--mj");
			}
		}

		public void ReceiveClient()
		{
			int bytes=0;
			byte[] bb=new byte[256];
			while(true)
			{
				try
				{
					bytes=client.Receive(bb,bb.Length,0);
				}
				catch
				{
					Initiator.richTextBox1.AppendText("error reading otherclient data");
					break;
				}
				if(bytes==0) break;
				string mystring=System.Text.Encoding.BigEndianUnicode.GetString(bb,0,bytes);
				if(mystring=="GoodBye")
				{
					break;
				}
			}
			Initiator.richTextBox1.AppendText("多余人退出1个。\n");
			client.Shutdown(SocketShutdown.Both);
			client.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -