public void SocketMethod()
{
threadRunning = true;
if (tcp.Connected)
{
bool checkValue = false;
string newBuffer = "";
string value = tcp.ReadString(Encoding.ASCII).Replace("\0", "");
for (int i = 0; i < value.Length; i++)
{
if (value[i] != ';' && !checkValue)
{
socketBuffer += value[i];
}
else
{
Global.Output += socketBuffer;
if (socketBuffer.Contains("move"))
{
var vals = socketBuffer.Split(':');
foreach (var t in Touches)
{
int id = (int)(long.Parse(vals[2]) % int.MaxValue);
if (t.Id == id)
{
string[] pos = vals[1].Split(',');
t.Position.X = float.Parse(pos[0]) * Global.ScreenSize.X;
t.Position.Y = float.Parse(pos[1]) * Global.ScreenSize.Y;
}
}
}
else if (socketBuffer.Contains("touch"))
{
var vals = socketBuffer.Split(':');
var touch = new TouchPoint();
long l = long.Parse(vals[2]);
touch.Id = (int)(l % int.MaxValue);
touch.State = TouchState.Touched;
string[] pos = vals[1].Split(',');
touch.Position.X = float.Parse(pos[0]) * Global.ScreenSize.X;
touch.Position.Y = float.Parse(pos[1]) * Global.ScreenSize.Y;
Touches.Add(touch);
Touches = Touches;
}
else if (socketBuffer.Contains("cancel"))
{
var vals = socketBuffer.Split(':');
if (vals[1] != "null")
{
TouchPoint t1 = null;
string[] strings = vals[1].Split(',');
int[] ids = new int[strings.Length];
for (int o = 0; o < ids.Length; o++)
{
ids[o] = (int)(long.Parse(strings[o]) % int.MaxValue);
}
foreach (var t in Touches)
{
if (!ids.Contains(t.Id))
{
t1 = t;
break;
}
}
if (t1 != null)
{
t1.State = TouchState.Released;
//Touches.Remove(t1);
}
}
else
{
foreach (var t in Touches)
{
t.State = TouchState.Released;
}
//Touches.Clear();
}
}
socketBuffer = "";
}
}
}
threadRunning = false;
}
/// <summary>