I have created a python tcp server and i am using node.js socketio module to communicate between browser and tcp server. Hierarchically they are connected like: Browser->Node.js->Python TCP Server Browser<-Node.js<-Python Tcp Server I can connect with Node.js to Tcp Server, i can send messages but right after i send the first message i cant send any message from Node.js to TCP Server, similarly after i send a message from TCP Server to Node.js i cant send messages after the first message. My Node.js code:
var http = require('http');
var mysql = require('mysql');
var net = require('net');
var socketio = require('socket.io');
////////////////////////////////////////////////////////////////
// tcp socket
// Connection part to my python server
////////////////////////////////////////////////////////////////
var tcpClient = net.connect({port: 3001, host:"localhost"});
tcpClient.setEncoding("utf8");
tcpClient.on('connect',function() {
console.log('client connected');
tcpClient.write('node - tcp server a bağlanıldı!');
});
tcpClient.on('data', function(data) {
console.log("tcp den gelen mesaj = "+ data.toString());
});
tcpClient.on('end', function() {
console.log('client disconnected');
});
tcpClient.on('error', function(data) {
console.log("error = " + data);
});
////////////////////////////////////////////////////////////////
// web socket
////////////////////////////////////////////////////////////////
var io = socketio.listen(3000);
io.sockets.on('connection', function (socket) {
socket.on('sendMessage', function (data) {
tcpClient.write("node - sendMessage");
console.log(data);
});
socket.on('login', function (data) {
tcpClient.write('node - login');
console.log(data);
});
});
I have checked my Python TCP Server with Python Client which i coded and everything seems alright. What might be the problem? Thanks in advance.