I am using TCP sockets to communicate data between a server and client program using a specific port number on the same computer (localhost).
I need a software that can capture the data being sent/received through that socket?
(or)
What's the simplest way of sniffing packets from a specified port in Java?
I suggest using Wireshark. It's easy to use and runs on many platforms.
http://www.wireshark.org/
If you are up to some coding (and not just running the wireshark/tcpdump) then you have few choices. If you want stick to Java, then the only (?) option to use raw sockets is via JNI and there are few libraries that can help, for example:
jNetPcap - wrapper around the native libpcap/winpcap libraries, exposing all of their functions and structures
RockSaw - API for using raw sockets
The easiest way is to replace the InputStream/OutputStream from a socket in one of the programs with a proxy implementation, that either prints/logs or "tees" to the original and a print/log stream.
But there's plenty of sniffers out there if you really want to get messy.
If you don't mind getting down and dirty with the command line you could try netcat.
It'll let you listen on a port and dump the output to a file if you like.
You can also make it send fake data and record the response.
I often use it as a pretend HTTP proxy (and configure Firefox to use it) to discover what is being sent over the wire.
Tcpdump can also be used directly, if the volume of traffic is not high, obviating the need to use wireshark. Just something like
tcpdump -ni lo0 port 1234
should be all you need (lo0 is the loopback interface on all Unix/Linux systems; also change the port number of course).
Run your program like so:
java -Djavax.net.debug=all helloworld.java
The switch is fully documented on the Oracle JSSE page
Pros:
Much simpler than other suggested solutions (requires no external software)
Can also decrypt/dump TLS/SSL connections :)
Cons:
This will only work if you are using classes from java.net.* e.g. OutputStream or InputStream This will not work if you're using raw sockets. This is documented in the link.
Believe this may only work on the Oracle JDK.
You can use tcpdump that gives you a variety of options. You save the capture in a .pcap file with the -w option and when you are done you open that file with wireshark. The advantage of this way is that you can capture a high rate of packets per second without affecting the overall performance of your pc (even if it is low end).
Related
Both grpc-java and grpc-c++ have the support for in-process channel, which is used if grpc client and server are in the same process.
So I have a question, is it possible to use java client to call c++ server in the same process using in-process channel?
No. The inprocess channels in each language are language-specific. You would need to use a normal channel and a port of localhost.
While it might be possible to use socketpair() to do something similar, it would require some effort to get working.
Has anybody successfully interfaced Medical Lab devices like Cell Counters /ABG instruments to mirth connect using ASTM 1381-02 or similar protocols over serial port. I am working on a small project. I need the data transmitted by the machine in ASTM format to a text file/ to a database and I cannot afford to pay $30000 for mirth commercial support. I need a low cost or open source solution.
I was expecting MLLP listener to be off use but it seems to work with TCP and I have to make it work purely on serial communication.
Secondly
I tried writing ASTM serial data receiver in Java. But control characters such as ACK, STX, ETX, ETB, and other delimiters are not visible in terminals be it in Win 7 cmd or Netbeans/Eclipse console. Making me helpless in parsing the data.
Any help will in right direction be deeply appreciated.
If you are under Linux environment you may use COM port redirector to a given TCP port and use Mirth's TCP Listener to intercept that flow.
E.g., to pipe the serial port through netcat:
netcat ipaddress port < /dev/ttyS0
Or using socat:
socat pty,link=/dev/virtualcom0,raw tcp:ipaddress:port&
(check for correct parameters)
I recognize 2 problems:
First, is it possible to raise an ftp service on the windows PC? if so, you only need to create a file reader addressed to ftp to capture the txt with the ASTM.
Second, to determine the characters of start and end of message I recommend you read the information of the provider, if you do not have it available, I suggest you use notepad ++ to see the hidden features. I hope you help.
Just FYI there is a commercial extension available that provides ASTM E1381 support: https://www.nextgen.com/products-and-services/integration-engine?extension=astm-transmission
While looking for ICE/STUN libraries for a peer-to-peer Java application, I ran into a problem. I needed to be able to ensure reliable delivery. All Java ICE libraries that I could find offered UDP hole punching (via the STUN protocol), but not TCP hole punching. I want peers to be able to reliably send files to one another over a network without needing a server, but UDP is not reliable. How do I get reliable, cross platform, peer-to-peer data delivery?
I have done a little research and have found this solution, know as "pseudo-TCP" - for example:
http://nice.freedesktop.org/libnice/libnice-Pseudo-TCP-Socket.html
Pseudo-TCP is reliable and also available in Java,
See:
https://github.com/opentelecoms-org/ice4j/blob/master/test/test/IcePseudoTcp.java
(^ from the ICE4J library^)
And also:
https://code.google.com/p/ice4j/source/browse/trunk/src/org/ice4j/pseudotcp/PseudoTcpSocket.java?r=335
I need to send data from my machine to a remote server over tcp and I need the data to be fragmented (it's a test). That explains the reason I am looking for a way to change the segment size to a small number.
I have googled around and I found that we can set MSS using iptables
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss some-number
However, after more googling, it seems like that solution is used to tell the server the TCP segment size that my machine can accept versus setting the segment size on the tcp packets/segments that my machine is sending over to the server.
I also learnt about MTU and how to change it, but that doesn't seem to be what I want because I need/want to cut my data up in a higher level (in the transport level). My questions are 1) how can I set MSS for TCP segments that my machine is sending? 2) is it possible to do it using Java?
Sorry for these newbie questions.
In C you can do this using by setting the TCP_MAXSEG socket option; see man 7 tcp.
In Java, the relevant socket option is not exposed in the standard Socket APIs. However there is a hint in that page that you might be able to set other options if you implemented a non-standard SocketImpl class.
Just set a small socket send buffer size, if you can.
given a flash application that opens a socket connection to a webserver, is it possible to reads packets exchanged with a java application, without redirect all the flash traffic ( that is, without programming a socket proxy)?
What you are trying to do requires lower level network analysis than sockets. Namely libpcap and its Java bindings , jNetPcap. This will let you capture packets much in the same way wireshark does, but from Java. The other options are analysing Wireshark logs after an experiment and that can get clunky quite quickly. You may also consider writing a custom wireshark dissector.
The only way I can think is to modify the hosts file to list your Java server address as if it was the destination address.
BTW if your are only interested in examine the network traffic for that app, you could also use fiddler