所以我最近一直在做一个广播控制服务器,但是我在读台词的时候遇到了一些问题。当连接进来时,我正在创建一个新线程,这就是处理连接的地方。所有数据都在被调用的url中提供。例如: /controllerupdate/?_=1597968275949
或者 /api/
. 它们根据url从混合器返回不同的内容。其他所有内容的处理都是最小的(平均<50ms)。
然而 String line = br.readLine()
通话时间最长为700毫秒,这是广播时最长的通话时间。
下面是代码块:
@Override
public void run() {
String path = "";
try {
//BufferedReader br = new BufferedReader(new InputStreamReader(this.is));
BufferedReader in = new BufferedReader(new InputStreamReader(this.s.getInputStream()));
long timeIn = System.currentTimeMillis();
//String request = br.readLine(); // Now you get GET index.html HTTP/1.1
String line;
line = in.readLine();
long t = (System.currentTimeMillis() - timeIn);
String[] requestParam = line.split(" ");
path = requestParam[1];
if(t > 50) {
System.out.println("T1: " + path + " :: " + t);
}
//Rest of the processing code is here
} catch (Exception e) {
e.printStackTrace();
}
}
此代码打印出以下内容:
Listening for connection on port 8080 ....
1597968951950 :: T1: /controllerupdate/?_=1597968950775 :: 187
1597968952013 :: T1: /api/ :: 766
1597968953450 :: T1: /controllerupdate/?_=1597968950778 :: 203
1597968953950 :: T1: /api/ :: 453
1597968954950 :: T1: /controllerupdate/?_=1597968950781 :: 203
1597968955950 :: T1: /api/ :: 703
1597968956450 :: T1: /controllerupdate/?_=1597968950784 :: 203
1597968956950 :: T1: /api/ :: 125
1597968957951 :: T1: /controllerupdate/?_=1597968950787 :: 204
1597968958951 :: T1: /api/ :: 345
1597968959450 :: T1: /controllerupdate/?_=1597968950790 :: 203
1597968960950 :: T1: /controllerupdate/?_=1597968950793 :: 203
1597968960950 :: T1: /api/ :: 453
连接的程序是c程序:
以下是执行请求的函数及其调用方式:
private async Task<String[]> doGetRequestWithError(String url)
{
if (!url.StartsWith("http"))
{
url = "http://" + url;
}
//Console.WriteLine(url);
try
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage result = await httpClient.GetAsync(url).ConfigureAwait(false);
String error = result.StatusCode.ToString();
String content = await result.Content.ReadAsStringAsync();
return new String[] { content, error };
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
Console.WriteLine("ERROR: " + url);
}
return new string[] { "", "" };
}
呼叫人:
Task<String[]> tsk = this.doGetRequestWithError(this.server + "/mixer?id=" + this.id + "&function=next");
尽管日志中出现的问题是来自ajax调用:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xml = this.responseXML;
var inputs = xml.getElementsByTagName("input");
var transitions = xml.getElementsByTagName("transition");
var numInputs = inputs.length;
var numTransition = Math.min(transitions.length, 4);
var names = [];
var types = [];
var isTitle = [];
var transNames = [];
inputsTmp = inputs;
for(var i = 0; i < numInputs; i++){
...
}
for(var i = 0; i < numTransition; i++){
...
}
...
$.getScript("http://" + server + "/controllerupdate/?refresh=1");
playbackUpdater();
window.setInterval(controllerUpdate, 500);
window.setInterval(playbackUpdater, 1000);
}
};
xhttp.open("GET", "http://" + server + "/api/", true);
xhttp.send();
这么说来,我只是想知道我哪里做错了?我以前从没遇到过这样的问题!
提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!