Added extra methods for string sending and receiving

This commit is contained in:
2015-10-02 11:54:49 +02:00
parent 167d186076
commit 063264b1e3
+16 -1
View File
@@ -14,15 +14,30 @@ namespace ErgometerLibrary
client.GetStream().Flush();
}
public static void SendString(TcpClient client, string command)
{
byte[] b = Encoding.ASCII.GetBytes(command);
client.GetStream().Write(b, 0, b.Length);
client.GetStream().Flush();
}
public static NetCommand ReadNetCommand(TcpClient client)
{
byte[] bytesFrom = new byte[(int) client.ReceiveBufferSize];
client.GetStream().Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
String response = Encoding.ASCII.GetString(bytesFrom);
string response = Encoding.ASCII.GetString(bytesFrom);
NetCommand net = NetCommand.Parse(response);
return net;
}
public static string ReadString(TcpClient client)
{
byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize];
client.GetStream().Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
string response = Encoding.ASCII.GetString(bytesFrom);
return response;
}
public static IPAddress GetIP(string ipstring)
{
IPAddress ip;