我的html页面中有三个按钮连接到php脚本,它们使用套接字连接将命令发送到另一个应用程序。
1)当接收命令的应用程序和xampp服务器在本地主机上运行时,它工作正常,但是当我尝试在网络上发送命令时,它有时会工作,有时却不起作用。
2)这可能是什么原因。
button1的代码
<?php
// Fill up array with names
$q=$_GET["q"];
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$host = $_GET["vz"];
$port=6100;
$buffer=$q ."\0";
$len= strlen($buffer);
socket_connect($sock, $host, $port);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
$buffer='COMMAND HERE';
$len= strlen($buffer);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
echo( socket_read($sock, 65535) );
socket_close($sock);
?>
Run Code Online (Sandbox Code Playgroud)
按钮2的代码
?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$host = $_GET["x"];
$port=6100;
$buffer='COMMAND HERE';
$len= strlen($buffer);
socket_connect($sock, $host, $port);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
$len= strlen($buffer);
socket_sendto($sock, …Run Code Online (Sandbox Code Playgroud) void sendCommand(float t,char* cmd)
{
std::clock_t endwait;
double endwait = clock () + t * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
if( clock() < endwait)
printf("\nThe waited command is =%s",cmd);
}
void Main()
{
sendCommand(3.0,"Command1");
sendCommand(2.0,"Command2");
printf("\nThe first value")
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想延迟功能,但我的应用程序应继续运行。
在上面的代码中,我要先打印第一个值。比我想要Command2要打印,而Command1应该是最后要打印的。
尽管设置了 setStandardButtons(0); 它不会关闭 msgBox。
QMessageBox msgBox;
msgBox.setText("My List");
msgBox.setStyleSheet("QDialog { border: 1px solid black;}");
msgBox.setStandardButtons(0);
QTimer::singleShot(5000, &msgBox, SLOT(close()));
msgBox.exec();
Run Code Online (Sandbox Code Playgroud) 我有一个类,我想要一个向量在程序的整个生命中都活着,所以我正在使用静态向量。
请查看我的代码,并告诉我它们是否是使用静态变量的更好方法。
static std::vector<std::string> Stack;
class Test
{
public:
void AddStack(std::string str)
void PopStack()
};
void Test::AddStack(std::string str)
{
Stack.insert(Stack.end(),str.begin(),str.end());
}
void Test::PopStack()
{
if(!Stack.empty() )
{
Stack.pop_back();
}
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以在代码中解释下面一行的含义
while (ss >> temp)
std::string str = "123:234:56:91";
for (int i=0; i<str.length(); i++)
{
if (str[i] == ':')
str[i] = ' ';
}
vector<int> array;
stringstream ss(str);
int temp;
while (ss >> temp)
array.push_back(temp);
Run Code Online (Sandbox Code Playgroud)