private static ReadString ( Socket socket, System.TimeSpan timeout ) : string | ||
socket | Socket | The |
timeout | System.TimeSpan | The timeout to apply to individual reads. |
리턴 | string |
private static string ReadString(Socket socket, TimeSpan timeout)
{
var text = new StringBuilder();
var buffer = new byte[1];
while (true)
{
if (SocketAbstraction.Read(socket, buffer, 0, 1, timeout) == 0)
{
// SOCKS client closed connection
return null;
}
var byteRead = buffer[0];
if (byteRead == 0)
{
// end of the string
break;
}
var c = (char) byteRead;
text.Append(c);
}
return text.ToString();
}
}