The TCP socket programming code for NodeJs given at [link][1] works fine when server and client are on the same computer.
However when I run the client and server on two separate computers connected with a single Ethernet cable to the two Ethernet ports of the two computers, the client is unable to connect to the server! The have disabled the firewall on the server which is a 64 bit Windows 10 machine. The client is a 32 bit windows 7 old machine . When I start the server it starts, but when I connect the client with the IP address of the server and correct port number, it gives ECONNREFUSED error on the client)!
I am able to ping the two computers from each other. Also a Java based simple socket client and server programs are able to communicate with each other on the connection. But the NodeJs based TCP socket program given above doesn't work across the two computers. Any idea what could be the problem.
[1]: https://www.hacksparrow.com/nodejs/tcp-socket-programming-in-node-js.html
Related
I’m using the python socket module on a Mac.
How do I connect two computers using the same router? I need a TCP socket with fast data passing between.
When I tried just hooking two computers up by their private ip address, then I got a Connection Refused error. How do I do this?
You can check first whether connection is allowed between two devices by going to one device and running telnet.
telnet <Private-IP-of-Second-Device> <Port>
If this shows connected then connectivity is good and issue exists with the socket module you have written.
If this fails you can try checking the firewall by going to System Preferences > Security & Privacy > Firewall.
I'm working on a custom yocto Linux for a Raspberry PI 3 and try to get the WIFI connection working with SSH. However when trying to connect from my PC (Ubuntu 19.10, SSH OpenSSH_8.0p1 Ubuntu-6build1, OpenSSL 1.1.1c 28 May 2019) to the PI on which Dropbear v2019.78 runs, the connection attempt times out. But only when I try this via SSH, and via wlan0. Other TCP/IP traffic works, and also using the same participants but with eth0. As this is for a robot, I would prefer to not use a tether though...
To try & debug this, I
enabled a serial console so I can work on the PI
disabled eth0
started a tcpdump on the PI (ip.host == 192.168.0.105)
started a tcpdump on the PC (ip.host == 192.168.0.106)
used a dirt-simple TCP/IP socket example written in Python (taken from https://realpython.com/python-sockets/#echo-server) to verify I can in fact communicate. The transmission is successful. I am aware that the example is lacking (no proper protocol etc), but that's not the point of it. It just works enough. The PI runs the server listening on port 2222.
attempted a SSH connection, it timed out.
I filtered the resulting PCAP down to contain just TCP, as there is other information (e.g. Dropbox discovery) that I don't think matters and might potentially be information leaking. On the host side (enp4s0-tcp-and-pi.pcap) I also filtered with ip.host == 192.168.0.105 to only contain any traffic to the PI.
Another note on my setup here: I use a TP-Link router which LAN ports the PC is connected to, and who provides the 2.4GHz WIFI for the PI. So both are part of the same subnet, and no special routing or anything is configured.
Also I stopped the dropbear daemon and adapted my Python code to use port 22. It works.
I'm only broadly aware of the inner workings of TCP, so I can't really make much sense of the things I see here. Any insights are more than welcome.
https://www.dropbox.com/s/5o4rqr5zdws2wq7/wlan0-tcp-only.pcap?dl=0
https://www.dropbox.com/s/amypjtk1nvja4qb/enp4s0-tcp-and-pi.pcap?dl=0
I have written code using sockets in python in two devices , one is programmed with client code(desktop) and another one is server code (laptop) both are connected over wifi , in client code i have given server ip address with port number, any thoughts on whats wrong??
I want to create a sort of remote control from my smartphone to my pc. I've created a server in my pc written with nodejs (using expressjs) and listening in a port. I want to make an app for my smartphone with cordova but I don't know how the app can know automatically the ip address of the server running in pc in my local network.
To my knowledge the best approach is to create a UDP server listening for broadcasts and send an UDP broadcast to the network segment from your APP. I have this working with Python. As long as your local router/access point is not blocking UDP broadcasts you should be fine.
I want make my server only accept one connection from a device(that means people can not open several browsers to connect my server), and I use client ip to identify connections. The question is if two devices are from the same ethernet their ip address will be the same(so they can not connect to my server the same time).
I tried to use socket.request.connection.remotePort to get the client port, but it shows different every connection even in the same browser.