Server-client chat program - VMware on the same machine - c

I'm trying to create a server-client chat program in c for Linux.
Considering I only have one computer (a power house at that) I'm trying to create it so I can talk to a server with vitual machines running ubuntu. The host OS is windows 10.
I have booted up two different vitual machines with ubuntu (using VMware) and set the network connection to be bridged.
I have the server program working, sorta, in that it connects to a socket (5000) and listens to wait for a client to connect.
On the client I run the client and it never seems to connect to the host and I'm not sure why. I'm not sure if I need to specify the IP address or port number or what (I'm totally new to this). This is supposed to be a TCP connection that works will work within all machines within the subnet.
Here is what I have for the server:
Server-chat.c
Here is what I have for the client:
client-chat.c
After I run the server I get to the listen part.
I switch to the client running VM and run my client program "./client-chat 127.0.0.1"
assuming that's what I need for it to connect but apparently not. Any direction or resources would be much loved.

Related

Connect to host from VSCode session running in container

I'm using a container to develop for an embedded system. To interact with the debugger I need openocd running on the host machine (as it needs USB access, and it's on a Windows machine therefore I can't access the USB port from the container), and connect to it with a gdb running in the container. I'd like to know if it is possible to forward/connect to a port from the host machine - from all that I've read until now this does not seem to be possible?
My current workaround is to run an SSH server in the container, forward it's port and open an SSH connection from the host to the container with reverse forwarding the openocd port. But that is quite a bit more convoluted than I'd like.
Just exposing the port to the local network and connecting via the public IP came to mind as well, but our corporate firewall blocks that.

Why can't I connect to my create-react-app local development server from my other computer?

I have a react client running locally on my machine using react-scripts. I can work with it normally on that machine. I also have a nodeJS server running on a different port. I figured I should be able to connect to these from my other computer or cellphone and I can connect to the server using my local IPv4 address + server port, but when I try to connect to the client using the same address + client port I get a loading spinner in the browser tab and the connection times out after some time.
I figured it might be a firewall issue so I added an inbound rule (and an outbound one though I don't think that should do anything) on the machine running the client+server letting all traffic through the relevant port but this changed nothing. When I do a network diagnostic using chrome from the tab where I can't open the client it tells me the webpage is online but isn't responding. I get the same behavior when connection from my cellphone.
One thing that might be of note is that when I serve the build folder of my app through my NodeJS server, the app opens just fine on the other computer using the server port but I don't want to have to build my app after every change manually.
What could this be down to?
EDIT: Forgot to mention, all devices are on the same router. The laptop running the servers and the cellphone are connected via wireless and the PC is connected via ethernet.

C: Why does this server / client setup only work inside one computer?

I'm new to networks and I'm wondering why this TCP Server-Client implementation in C
only works on one computer? (1)
I mean I have to open one terminal for the server program and another one for the client program. But why this doesn't work between computers? Starting the server program on one computer and the client program on another computer.
How we need to modify the code to work between computers? (2)
And what are great resources to start on the whole topic? (3)
It will work on other computers.
Just ensure you do the followings:
Two computer be on a network and see each other with PING
Change 127.0.0.1 in client program with the IP of the server machine
Check listening ports with netstat of server machine and Make sure the port 8080 is in Listening mode
Make sure there is no firewall in server machine, you can use telnet in client machine to make sure port on the server is accessible.
Before test your C program, make sure the communication is OK between servers by third party application. For example, make an echo server in linux by ncat -l 2000 -k -c 'xargs -n1 echo' on port 2000.
It highly recommended change Port from 8080 to another one (for example 8192). 8080 is used with some third party applications.
The host used by the client is hardcoded:
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
You can change the host into the code to reach another computer, or you can read it from command line to have a more flexible use.

rdc windows10 to headless VM using a port number fails

I upgraded my desktop machine from windows 8 to 10 and now I'm unable to connect to any of my Vms (hosted on another server) using RDC.
I have one server(Ubuntu no GUI) that host multiple VM's(windows and Linux w and w/o GUI) using VirtualBox. From my laptop I normally connect with RDC using the host(server) ip followed by port number (192.168.0.2:3396 assigned during create VM process) works fine, at that point I adjust network setting(static ip) for the LAN and exit. etc etc..
On the windows 10 desktop I receive and error; This computer can not connect to the remote computer. I can however connect with the ip address (192.168.0.5) no port. this part is fine for existing Vms that have static ip. I need to connect and assign the ip.
Thanks for any feedback or suggestions

Socket server not accepting clients from other computers (connect failed: 10060)

I am trying to use this c socket class, but it only works when I use it on my own computer.
Desktop only
Server is started like this: cSocketServer -p:2030 -i:192.168.178.22
Client connects: cSocketclient -p:2030 -s:192.168.178.22
Works fine.
Desktop server, laptop client
Server: cSocketServer -p:2030 -i:192.168.178.22
Client: cSocketclient -p:2030 -s:192.168.178.22
Exact same as above, but this fires the connect failed: 10060 error. Which essentially means it timed out.
Desktop only (external address)
Server: cSocketServer -p:2030 -i:192.168.178.22
Client: cSocketclient -p:2030 -s:xx.xx.xx.xx
Where xx.xx.xx.xx is my external ip address.
Same error: connect failed: 10060. Port 2030 is definitely open and accessible, because I tested it with a few unrelated applications that allow their users to choose their own ports (like utorrent). While those run, whatismyip.org states port 2030 is open. But when I run my application it sais it Timed-out. Those applications do not have any special privileges in the firewall.
But even if I did mess up some firewall/router settings (which I'm fairly sure I didn't) that wouldn't explain why I can't connect to the server from within my local network. Other services (such as file sharing) work fine so there is definitely a connection between the 2 computers.
Both client and server run on windows 7 64-bit.
Also; for some reason, each client that connects gets their own inbound port assigned or something? Is that normal? When clients connect the server states;
Accepted client: 192.168.178.22:55156
Accepted client: 192.168.178.22:55164
Accepted client: 192.168.178.22:55176
What's that all about?
If two TCP connections have the same source IP, destination IP, source port, and destination port, there would be no way to tell them apart. To ensure they differ somewhere, clients typically assign a unique source port to every outbound connection they make.
As for the errors, you really need to do some troubleshooting. Do the listening sockets show up in a 'netstat'? Do you get the same problem with the firewalls turned off? Are the server and client on the same LAN (for the internal address case)? Is port forwarding enabled and working in the router (for the external address case)?
My bet is that the external address case won't work because you haven't configured the port to be forwarded by your router or your router doesn't support hairpin (local access to external IP). Other programs may work because they support UPnP or don't rely on hairpin (all access to external IPs come from outside your LAN).
I have no immediate explanation for why your desktop-to-laptop won't work inside your LAN. Are you sure both computers are in the same LAN? Can they ping each other?
Get rid of the -i argument to the server, or specify 0.0.0.0 and fix the code so that isn't considered an error, which is itself an error.

Resources