Post by scattered on Jul 9, 2017 9:16:39 GMT
I have 2 apps.
1 - Windows server program
2 - Android Client program
Android app send a char[]. It's size/length is 8. every char represent '1' or '0'. so the whole object is like 00000000, so any character inside it could be '1' or '0'.
So my windows program read this data and act according to the values.
below is my windows program's code,
So if I run the above code it works perfectly, it prints the data I receives from the android app. But when I un-commented the methods there are and run the program, it has a big time delay. Even the textbox gets delay only after un-commenting of the above lines.
It's as if joystick.SetBtn makes the program slower. and there's one thing, I tried restarting my server program, and couple of times I got it working well. But after restarting it has a big delay. I tried Monitor vJoy and the joy.cpl but there's still the delay.
Could it be because I'm doing fastly? Please note that this happens only after un-commenting the lines above in the code
1 - Windows server program
2 - Android Client program
Android app send a char[]. It's size/length is 8. every char represent '1' or '0'. so the whole object is like 00000000, so any character inside it could be '1' or '0'.
So my windows program read this data and act according to the values.
below is my windows program's code,
#define ROBUST
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using vJoyInterfaceWrap;
namespace WifiJoystick
{
public partial class Form1 : Form
{
private char[] charArray = new char[8];
private StreamReader inOpt;
private vJoy joystick;
private uint id = 1;
public Form1()
{
InitializeComponent();
}
private void startBtn_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(StartServer));
thread.Start();
}
void StartServer()
{
Log("Running");
TcpClient client = new TcpClient();
TcpListener server = new TcpListener(IPAddress.Any, 8888);
server.Start();
client = server.AcceptTcpClient();
Log("Client connected");
inOpt = new StreamReader(client.GetStream());
Thread thread = new Thread(new ThreadStart(handleTheShit));
thread.Start();
}
void handleTheShit()
{
joystick = new vJoy();
long x = 0;
long y = 0;
joystick.GetVJDAxisMax(1, HID_USAGES.HID_USAGE_X, ref x);
joystick.GetVJDAxisMax(1, HID_USAGES.HID_USAGE_X, ref y);
joystick.SetAxis((int) y / 2, 1, HID_USAGES.HID_USAGE_Y);
while (true)
{
inOpt.Read(charArray, 0, 8);
/*
///Button A
if (charArray[0] == '1')
{
joystick.SetBtn(true, 1, 1);
}
else
{
joystick.SetBtn(false, 1, 1);
}
///Button B
if (charArray[1] == '1')
{
joystick.SetBtn(true, 1, 2);
}
else
{
joystick.SetBtn(false, 1, 2);
}
///Button C
if (charArray[2] == '1')
{
joystick.SetBtn(true, 1, 3);
}
else
{
joystick.SetBtn(false, 1, 3);
}
///Button D
if (charArray[3] == '1')
{
joystick.SetBtn(true, 1, 4);
}
else
{
joystick.SetBtn(false, 1, 4);
}
*/
Invoke((MethodInvoker) delegate
{
logBox.Text = charArray[0].ToString() + charArray[1].ToString() + charArray[2].ToString() +
charArray[3].ToString() + charArray[4].ToString() + charArray[5].ToString() +
charArray[6].ToString() + charArray[7].ToString(); // runs on UI thread
});
}
}
private void Form1_Load(object sender, EventArgs e)
{
joystick = new vJoy();
VjdStat status = joystick.GetVJDStatus(id);
Text = joystick.GetVJDButtonNumber(id).ToString();
joystick.AcquireVJD(1);
joystick.ResetVJD(1);
}
}
}
So if I run the above code it works perfectly, it prints the data I receives from the android app. But when I un-commented the methods there are and run the program, it has a big time delay. Even the textbox gets delay only after un-commenting of the above lines.
It's as if joystick.SetBtn makes the program slower. and there's one thing, I tried restarting my server program, and couple of times I got it working well. But after restarting it has a big delay. I tried Monitor vJoy and the joy.cpl but there's still the delay.
Could it be because I'm doing fastly? Please note that this happens only after un-commenting the lines above in the code