Added extra methods for string sending and receiving
This commit is contained in:
@@ -14,15 +14,30 @@ namespace ErgometerLibrary
|
|||||||
client.GetStream().Flush();
|
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)
|
public static NetCommand ReadNetCommand(TcpClient client)
|
||||||
{
|
{
|
||||||
byte[] bytesFrom = new byte[(int) client.ReceiveBufferSize];
|
byte[] bytesFrom = new byte[(int) client.ReceiveBufferSize];
|
||||||
client.GetStream().Read(bytesFrom, 0, (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);
|
NetCommand net = NetCommand.Parse(response);
|
||||||
return net;
|
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)
|
public static IPAddress GetIP(string ipstring)
|
||||||
{
|
{
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
|
|||||||
Reference in New Issue
Block a user