Php客户端和Java多线程服务器套接字两次运行(两个线程)

时间:2016-04-27 15:32:05

标签: java php multithreading sockets

我创建了一个php客户端和一个java多线程服务器套接字。我的问题,当我用php客户端连接到java服务器(socket)时,java创建两个线程,并运行两次。当我连接java客户端或telnet,到服务器,它是正确的,只创建一个线程。 对不起我的英文不好。

PHP:

function generateChart() {
  var chart;
  var Category = [{
    key: "Stuff",
    values: []
  }]; 
  console.log(data.rows[0].mockupData[0].Data)
  var thisDataSet = data.rows[0].mockupData[0].Data;
  for (var i = 0; i < thisDataSet.length; i++) {
    //for (var key in data.rows[0].mockupData[0].Data) {
    console.log(thisDataSet[i]) 
    Category[0]["values"].push({
      "label": "Statistic",
      "value": thisDataSet[i].Category
    });  
  }
  console.log(Category) 
}

爪哇:

$PORT = 777;
 $HOST = "localhost";
 $sock = socket_create(AF_INET, SOCK_STREAM, 0)
 or die("error: could not create socket\n");
 $succ = socket_connect($sock, $HOST, $PORT)
 or die("error: could not connect to host\n");
 $text = "Hello, Java!"; //the text we want to send to the server
 socket_write($sock, $text . "\n", strlen($text) + 1) 
 or die("error: failed to write to socket\n");
 $reply = socket_read($sock, 10000, PHP_NORMAL_READ)
 or die("error: failed to read from socket\n");
echo $reply;

0 个答案:

没有答案