server.js
var net = require('net');
var client = net.connect(4567, 'localhost', function() {
client.write("hello");
client.on('error', function(ex) {
console.log(ex); });
client.end();
});
client.java
server = new ServerSocket(4567);
client = server.accept();
InputStream input = client.getInputStream();
String inputString = MyClass.inputStreamAsString(input);
system.out.println(inputString); //inputString gives me "hello"
client.java是一个每5秒运行一次的时间调度程序,它会尝试从Node获取文本并打印它。我不想从Node关闭套接字,所以我可以在client.java已经运行时发送另一条消息。我有2个问题
我怎么能不在Node中结束我的套接字并能够向调度程序发送消息?
答案 0 :(得分:0)
您是否查看了网络模块的allowHalfOpen选项?
public class Recursive2 {
// int digit;
String temp;
public Recursive2(int d){
//digit = d;
temp = recursive(Integer.toString(d));
//System.out.print(recursive(temp));
}
public String toString(){
return temp;
}
public String recursive(String a){
String tempStr = "";
if(a.length() % 2 == 0){
System.out.println("Even number");
return "";
}
else if(a.length() == 1){
if(a.equals("1")){
tempStr = "0";
// tempStr += d;
}
else if(a.equals("0")){
tempStr= "1";
}
//System.out.println("Flipped d to" + tempStr);
}
else{
tempStr += new Recursive2(Integer.parseInt(a.substring(0,1))).toString();
tempStr += new Recursive2(Integer.parseInt(a.substring(1, a.length() - 1))).toString();
tempStr += new Recursive2(Integer.parseInt(a.substring(a.length()-1, a.length()))).toString();
}
return tempStr;
}