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

📄 15.3.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
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 );
}

⌨️ 快捷键说明

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