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

📄 15.2.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 15.2 Establishing a Defined Protocol
do
{
cmd = ReceiveData( s );
// determine which action to take based on response
switch( GetResponseCode( cmd ))
{
case( 300 ):
{
// client wants instructions on how to play
SendData( s, “200\r\nPick a number “ +
“between 1 and 100 and the server will “ +
“return if it’s too high, too low or “ +
“correct\r\n\r\n” );
break;
}
case( 301 ):
{
// client is guessing number
try
{
int guess = Int32.Parse(
GetResponseData( cmd ));
if( guess < curRandom )
{
SendData( s,
“401\r\nNumber is too low\r\n\r\n”);
}
else if( guess > curRandom )
{
SendData( s,
“401\r\nNumber is too high\r\n\r\n”);
}
else
{
SendData( s, “400\r\nCorrect! The “ +
“number is “ + curRandom +
“\r\n\r\n” );
bCloseConnection = true;
}
}
catch
{
SendData(s,”404\r\nInvalid guess!\r\n\r\n”);
}
break;
}
case( 302 ):
{
// client is quitting
bCloseConnection = true;
break;
}
default:
{
break;
}
}
} while( GetResponseCode( cmd ) !=
302 && bCloseConnection == false );

⌨️ 快捷键说明

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