《Microsoft Visual C# .NET 2003开发技巧大全》源代码

源代码在线查看: 15.3.txt

软件大小: 288 K
上传用户: rylzll
关键词: Microsoft Visual 2003 NET
下载地址: 免注册下载 普通下载 VIP

相关代码

				Listing 15.3 Receiving Client Data
				public static string ReceiveData( Socket client )
				{
				string data = “”;
				int bytesRecvd = 0;
				int totalBytes = 0;
				byte[] recvData = new byte[1024]; // 1k packet size
				do
				{
				bytesRecvd = client.Receive( recvData, 0,
				1024, SocketFlags.None );
				if( bytesRecvd > 0 )
				{
				data += Encoding.ASCII.GetString( recvData );
				totalBytes += bytesRecvd;
				}
				} while( bytesRecvd == 1024 );
				return data;
				}
				// methods to break apart protocol messages
				// extracts the numerical identifier at beginning of message
				public static int GetResponseCode( string response )
				{
				string code = response.Substring( 0, response.IndexOf( ‘\r’ ));
				return Int32.Parse( code );
				}
				// extracts extra message data
				public static string GetResponseData( string response )
				{
				return response.Substring( response.IndexOf(‘\n’)+1,
				response.LastIndexOf(“\r\n\r\n”)-response.IndexOf(‘\n’)+1 );
				}
							

相关资源