How to capture packets in localhost between two ports - sockets

I have two applications communicating on same machine (localhost) using socket. If application are on different machine I can use Wireshark. But how to capture packets on same machine.
I do not know on which port number application are communicating. Because I am using library calls and do not know lower level details.
We are having our application on Ubuntu and Windows XP.

On Linux you can use netstat to determine the ports that your application are using. Then you can use Wireshark to capture on the loopback interface (just enter your own IP address if 127.0.0.1 dont work).
Refer to: https://stackoverflow.com/questions/1566234/ for capturing on Windows.

Related

Developer exception starting a client-server model on Eiffel net

I'm trying to establish a connection using sockets between 2 PC's on the same LAN using the Eiffel Programming Language. I'm trying to run the examples that are by default on the installation directory of Eiffel Studio. However right now I'm trying to make it on the same machine by addressing to localhost (127.0.0.1).
It works perfectly on Linux (Ubuntu 15.10) but on windows 7 I'm getting an exception when I try to run the client program. The code of the exception is 24 Unable to establish connection. The server program runs just fine and I already got a connection between a client on linux and a server on windows. I didn't find a solution to this exception on the documentation nor on other sites. Here is a screencap:
Screencap of the debugger
Here is a link to the doc:
https://www.eiffel.org/doc/solutions/Two%20Machines
Thank you in advance.
The issue might be caused by the fact that some ports are used and others are reserved by the system. In particular the port range 0-1023 is designated for use by common system and network services. Ports beyond this range can also be registered (e.g., Service Name and Transport Protocol Port Number Registry or List of TCP and UDP port numbers). System security settings could also prevent applications from using specific port numbers.
The solution is to look for and to use port numbers that are available for user applications. Ports currently used on Windows can be found with netstat -an, what can be used is related to TCP/IP and firewall settings. The simplest approach is to try using some other port numbers, e.g. in the range 1024-49151.

TCP port without network adapter

I am intending to write some software modules that will all run on a single machine, and I would like for them to communicate with each other via TCP.
It is likely that the machine I am using will not have a physical network adapter. Will TCP connections to localhost be able to work correctly if there is no physical network adapter?
The operating system that I am running on is Linux for Tegra.
Thanks.

TCP Server on Computer. No connection established

I have 2 devices on the same network and I want to communicate via TCP on the same network. Device 1 is a computer running a Debian OS on virtualbox, and another is an android tablet. Interesting enough, my tablet acts as a server no problem via an app. Any other device on the same network can connect to the tablet. The computer on the other hand is not so cooperative. Running netcat -l -p 6667 on my computer should allow incoming connections to communicate with my computer via TCP on port 6667, but this is not the case. Netcat opens a socket but I can't connect to it in anyway. Is there an underlying reason as to why this does not work? All device are under the same router. I have disabled firewall on my computer as well.
From your information, i would say your problem is you need to set up port forward.
VirtualBox and VMware both create virtual machines with the NAT network type by default. If you want to run server software inside a virtual machine, you’ll need to change its network type or forward ports through the virtual NAT.
here is a guide that will show you how to Forward ports to virtual machine

ZeroMQ (0MQ) basic issue re connecting or binding to sockets

I'm using ZeroMQ on Windows, using C#, and am confused by a very basic networking question. I set up simplistic sample programs, one to PUBlish messages, the others use a SUB socket to receive them (the SUBscriber programs).
Works fine when both are on the same box. I used endpoint tcp://127.0.0.1:5000
As the next step, I put the SUBscriber program on a separate virtual machine (VM), to simulate using separate computers. I ran ipconfig to get it's IP address (on the guest os), 192.168.92.136
The host os has several network interfaces, one of which is the VMware Network Adapter VMnet1, with IP 192.168.92.1
On the host os, I ran the PUB program and connected the socket to 192.168.92.136, the IP address of the guest os.
On the guest os, I ran the SUB program and connected the socket to the IP of the host os. Did not work.
Then I changed the SUB program on the guest os to make it connect it to it's own IP address, ie that of the guest os - 192.168.92.136. Now it works!
Question: Why? I'm confused. But in a way it sort of makes sense: if that socket is for a service that attends to various clients that dynamically come and go, it doesn't know the IP address of each client. Therefore what the heck do you specify as the IP address for the SUB socket?! So connecting it to it's own host IP address does solve that concern. But the ZeroMQ Guide doesn't say this anywhere!
A related question is: if your host has multiple network interfaces, and each has it's own IP address, then if you connect your socket to some other host using the IP address of that other host - do you not need to specify which of those network interfaces you want to connect through? If so, how?
Incidentally, only one subscriber program seems to be able to connect at a time. The 2nd program to attempt to connect to it's SUB socket to the local IP address always gets a "Address is in use" error-message. I'm trying to make progress in small steps and learn this as I go.
Thanks for any help or advice.
James Hurst, JamesH at Designforge dot com

How does communication occur in java through TCP sockets on the same machine

I have two servers, written in Java, that communicate through sockets and TCP. The servers are both on the same Linux machine. If the servers were on different machines then data would have to go through network adapters and network cables, but since the servers are on the same machine how does the OS actually move data efficiently form one server to the other.
Generally, the messages will be sent over the loopback interface:
In TCP/IP a loopback device is a virtual network interface implemented in software only and not connected to any hardware, but which is fully integrated into the computer system's internal network infrastructure. Any traffic that a computer program sends to the loopback interface is immediately received on the same interface.
However, you can manage to configure your situation so that, for example, the server is referred to via an external IP address so that messages actually go out over the network before being routed back to the same machine.
If two programs are using TCP/IP to communicate on the same machine, they are probably connected through the loopback interface