removed clientId

This commit is contained in:
shinichi
2020-09-25 12:51:54 +02:00
parent dded1a5b24
commit 2139fcf2b2
3 changed files with 20 additions and 67 deletions

View File

@@ -11,7 +11,6 @@ namespace Client
private byte[] buffer = new byte[1024];
private int bytesReceived;
private bool connected;
private byte clientId = 0;
public Client() : this("localhost", 5555)
@@ -41,7 +40,7 @@ namespace Client
Console.WriteLine("enter password");
string password = Console.ReadLine();
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password), this.clientId);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
@@ -109,7 +108,7 @@ namespace Client
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes, clientId);
byte[] message = DataParser.GetRawDataMessage(bytes);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}
@@ -119,7 +118,7 @@ namespace Client
{
throw new ArgumentNullException("no bytes");
}
byte[] message = DataParser.GetRawDataMessage(bytes, clientId);
byte[] message = DataParser.GetRawDataMessage(bytes);
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
}

View File

@@ -36,7 +36,7 @@ namespace Client
/// <returns>if it sucseeded</returns>
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 6)
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
@@ -44,7 +44,7 @@ namespace Client
if (messageId == 1)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(6).ToArray()));
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
@@ -62,7 +62,7 @@ namespace Client
/// <returns>if message contains raw data</returns>
public static bool isRawData(byte[] bytes)
{
if (bytes.Length <= 6)
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
@@ -76,14 +76,13 @@ namespace Client
/// <param name="messageId"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
private static byte[] getMessage(byte[] payload, byte messageId, byte clientId)
private static byte[] getMessage(byte[] payload, byte messageId)
{
byte[] res = new byte[payload.Length + 6];
byte[] res = new byte[payload.Length + 5];
Array.Copy(BitConverter.GetBytes(payload.Length + 6), 0, res, 0, 4);
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
res[4] = messageId;
res[5] = clientId;
Array.Copy(payload, 0, res, 6, payload.Length);
Array.Copy(payload, 0, res, 5, payload.Length);
return res;
}
@@ -94,9 +93,9 @@ namespace Client
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] GetRawDataMessage(byte[] payload, byte clientId)
public static byte[] GetRawDataMessage(byte[] payload)
{
return getMessage(payload, 0x02, clientId);
return getMessage(payload, 0x02);
}
/// <summary>
@@ -105,9 +104,9 @@ namespace Client
/// <param name="payload"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(byte[] payload, byte clientId)
public static byte[] getJsonMessage(byte[] payload)
{
return getMessage(payload, 0x01, clientId);
return getMessage(payload, 0x01);
}
/// <summary>
@@ -116,9 +115,9 @@ namespace Client
/// <param name="message"></param>
/// <param name="clientId"></param>
/// <returns>the message ready for sending</returns>
public static byte[] getJsonMessage(string message, byte clientId)
public static byte[] getJsonMessage(string message)
{
return getJsonMessage(Encoding.ASCII.GetBytes(message), clientId);
return getJsonMessage(Encoding.ASCII.GetBytes(message));
}