Forum
Please or Register to create posts and topics.

stable TCP server in script block

I've implement a TCP server on script block for having a connection out of RTSA. my code for this is as follows:

 

///////////////////////////////////////////////////////

import {TCP,TCPServer} from "tcp.js"
import {Async} from "async.js"
var host = "localhost"
var port = 1001;
TCPServer.listen(null,port,(err_socket,socket) => {
if(err_socket)
console.log("socket error")
else{
Async.forever(cb => {
socket.accept((err_client,client)=>{
if(err_client)
console.log("accept error")
else{
console.log("Client Connected!")
client.receive().then((buffer)=>{
console.log(UTF8.decode(buffer))
client.send(UTF8.encode("Hello Client!"),(err_send)=>{
if(err_send)
console.log("send error")
})})}})})}})
/////////////////////////////////////////////////
It is written by the aid of your JavaScript documentation. and it simply works when I run the script and run my client out of the RTSA for one time!
So I think the problem is that the server is not always listening and it just run one time.
could you please help me to solve the problem?

++ when I called cb (using cb();) under the callback of socket.accept the problem has solved