简体   繁体   中英

tcp client with socket.io (nodejs)

I need a nodejs server connected to a C# application, i don't like using third-party libraries, so I've been trying using a TcpClient , the server is something like this:

var io = require('socket.io').listen(8000);
io.socket.on('connection',function(socket)
{
 console.log("connected");
}

and on the C# project:

var client = new TcpClient(Server,8000);
Socket s = client.Client;
if (!s.Connected)
{
   s.SetSocketOption(SocketOptionLevel.Socket,
   SocketOptionName.ReceiveBuffer, 16384);
   MessageBox.Show("disconnected");
}
else
{
   MessageBox.Show("connected");
   s.Send(Encoding.UTF8.GetBytes("something"));
}

for what i understood on the "something" i should write something that would trigger the "on('connection')" on the nodejs side, am i missing something?

PS: if you know a good third-party library for what i need you could mention it

实际上,服务器on('connection')应该在你构造TcpClient对象时触发,因为那是在连接发生时,而不是在你尝试发送一些数据的时候。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM