我已经尝试了一段时间,我希望多个客户端同时接收多个输入.
有一个问题,如果一个客户端说'print2all Hi',我希望服务器向所有客户打印"Hi".
我知道如何处理它来打印它,只是打印到所有客户端是问题.
这是我到目前为止所拥有的.
服务器
try{
try{
server = new ServerSocket(25565);
} catch (Exception e){
e.printStackTrace();
}
while (isListening){
new SocketThread(server.accept()).start();
}
server.close();
} catch (Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
SocketThread
try {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String inputLine, outputLine;
Processor kkp = new Processor();
out.println("Hi!");
while ((inputLine = in.readLine()) != null) {
outputLine = kkp.Proccess(inputLine,this.socket);
out.println(outputLine);
}
out.close();
in.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
客户
Processor p = …Run Code Online (Sandbox Code Playgroud) 我在HeidiSQL中运行的SQL代码一次又一次地运行,但是当我将它克隆到PHP并运行mysqli_query($ db,$ sql)时,它不起作用.
以下PHP/MySQL代码都是有效且完美的.
$sql = "select `ID`,`User` from (
select * from
(SELECT
`ID`,
`User`,
`BI`,
(@cnt:= @cnt + (`BI`/(select SUM(`BI`) from `ax`))) as `Entirety`
from `ax` as `t`
CROSS JOIN (SELECT @cnt := 0) AS var
order by `BI`
) d
where `Entirety`>(@rnd)
order by `BI`
) as `l`
cross join (select (@rnd := rand()) as `RandomValue`) as var2
limit 1;";
Run Code Online (Sandbox Code Playgroud)
然后我运行$ sql
$result = mysqli_query($db,$sql);
$results = mysqli_fetch_array($result);
Run Code Online (Sandbox Code Playgroud)
其中$ db是与MySQL服务器有效且开放的连接.但是当我这样做时,物体的回归
print_r($result);
Run Code Online (Sandbox Code Playgroud)
出来了
mysqli_result Object (
[current_field] => …Run Code Online (Sandbox Code Playgroud) 所以这就是问题,
我正在尝试使用jQuery加载图像以加快页面下载速度.为了实现它,我将以下代码作为图像,我想在页面加载后加载.
<img src="/pixel.png" new-img="/newimage.png"/>
Run Code Online (Sandbox Code Playgroud)
然后,要在文档完全加载后加载最终图像,我使用了以下内容.
$(document).ready(function(){
$("img").attr("src", $("img").attr("new-img"));
});
Run Code Online (Sandbox Code Playgroud)
这适用于单个图像,但我有多个图像要转换为此图像.当我尝试加载这样的多个图像时,我完全难以接受,它将所有图像设置为最后加载的图像.
我不确定,但是'$(this)'与它有什么关系?
JSFiddle:http: //jsfiddle.net/AeroMcDoom/8sxED/
所以我正在尝试使用进度条创建一个显示下载进度的下载程序.但我遇到问题,因为它实际上并没有更新进度条.基本上它保持白色,当它意味着蓝色.如果有人可以帮忙,代码如下.
JProgressBar progressBar = new JProgressBar(0, ia);
con.add(progressBar, BorderLayout.PAGE_START);
con.validate();
con.repaint();
progressBar = new JProgressBar(0, ia);
progressBar.setValue(0);
System.out.print("Downloading Files");
while ((count = in.read(data, 0, downloadSpeed)) != -1){
fout.write(data, 0, count);
if (count >= 2){
progressBar.setString("Downloading : " + ia + " @ " + count + "Kbs per second");
} else {
progressBar.setString("Downloading : " + ia + " @ " + count + "Kb per second");
}
progressBar.setValue(count);
con.add(progressBar, BorderLayout.PAGE_START);
try{
Thread.sleep(1000);
} catch (Exception e){}
}
Run Code Online (Sandbox Code Playgroud) java ×2
html ×1
javascript ×1
jprogressbar ×1
jquery ×1
mysql ×1
mysqli ×1
php ×1
printwriter ×1
serversocket ×1
sockets ×1
swing ×1