I wrote a game that has client-server architecture. A server first runs at port 12345. Two clients connect to port 12345 and they start exchanging messages.
I want to see what client sends to server and vice versa for testing purposes, without depending on my software. How can I see them?
Using Java on Ubuntu 14
You can use a network sniffer, for example on of these two:
tcpdump http://www.rationallyparanoid.com/articles/tcpdump.html
Wireshark https://www.youtube.com/watch?v=0DBZiKpbHO0
You can use sniffers like Wireshark.
Related
I am using an application called Splunk, which has 2 layers of data processing on separate systems. I can connect to both systems via putty and directly logging into the GUI.
Archiecture of the system attached
I want to monitor the output port on layer 1, and input port on layer 2 and find out the below information,
i. Raw data sent out of layer 1
ii. Raw data received into layer 2.
The two layers communicate using tcp.
I do not want to use an existing packet monitors/packet capture like tcpdump or winshark as I want to heavily customize the monitor to display various information. I want to write my own packet monitor in java
I want to know,
If layer 2 is listening to layer 1, can my program connect to the same port and print the raw text being sent? - the protocol is TCP
Is (1) possible for other protocols like udp, http and ftp?
(EDIT: Architecture attached
Info on the systems in case it is relevant,
system 1 is VMWare(Linux Ubuntu 4.4.10) running on a Windows machine.
System 2 is mac os.
Both systems have different IP addresses. I am connecting to both systems from the windows machine where vmware is running.
The two systems connect to the same wifi.
)
There are some packet capture libraries written in Java, jpcap, jNetPcap, and Pcap4J.
Both #1 and #2 are possible by these libraries, I think.
If you would pick Pcap4J I can help you. It's my library.
I have a requirement where I need to send message from multiple clients and those clients can be C clients or Java clients to server written in java.
Why I need to send over socket? Because there can be any process in any app on a same system who wants my app to capture there alarms and react accordingly.
Now, I can implement multiple Java clients who can connect to single Java server but how to do the same thing irrespective of it is Java client r C client.
If not socket programming, then what could be the other best way to make this communication happen
All low level network programming is written using sockets. you can have server written in any language communicate with client written in any language. To make this happen we have certain protocol which governs the communication like udp, tcp etc.
high level language provides api which will you to connect any server with single line of code without you needing to create socket. But in C you can create socket and connect it to the server. see this. All you need to know connect server and client is server ip and port...
While your requirements are very broad it looks a lot like a prime candidate for protocol buffers.
https://developers.google.com/protocol-buffers/
Language agnostic.
Platform neutral.
Fast.
Running on ZeroMQ (http://zeromq.org/) where you can push and pretty much run on top of everything.
my task is to receive UDP packets on an Google Compute Engine. Given is the port, which is 300 and I already have a simple Java program which can handle these UDP packets.
My problem now. Get the UDP packets to my Java program.
For that I don't know how to do this.
What I have tried so far ist to let the Java program direct listen to the port, which didn't work. I suspect the traffic from outside the GCE must be routed to the inside?
First make sure you've added a firewall rule on your GCE VM instance's network which allows incoming traffic for UDP protocol on port 300.
You can do this by going to the Developers Console, select your project, then Compute-> Compute Engine-> Networks, click on the right network and verify firewall rules (and tags as well if you used them). If the rule is not added, then add a rule for the traffic.
"gcloud" is a command-line tool which you can use it to list and verify your firewall rules as well [1]:
$ gcloud compute firewall-rules list
If the firewall rules are good, then use a simple troubleshooting tool like netcat to test if traffic is being forwarded to your VM instance.
1. Listing Google Compute Engine firewall rules
I recommend not using Java to process UDP. I experienced inexplicable short periods where all UDP traffic arriving was being lost. This was caused by garbage collection.
The architecture that works for me is to use a GCE VM with a C++ app receiving UDP data, then using libCURL, convert the data to HTTP and dispatch it to Google App Engine for processing. To make the UDP receiver scalable and tolerant, use network balancing and multiple VMs listening for UDP.
My issue is a protocol that identifies terminals by it's sending IP. I want to manage the connections of several terminals to this server using some kind of proxy that implements that protocol.
So I have Terminal A which is identified by the server by the IP 1.2.3.4 and Terminal B which is identified by the server using the IP 5.6.7.8. Now the proxy will be in a local network with Terminal A and B.
When Terminal A wants to reach the server, it will query the proxy and the proxy needs to send the request on behalf of Terminal A using IP 1.2.3.4 to the server
When Terminal B wants to reach the server, it will query the proxy and the proxy needs to send the request on behalf of Terminal A using IP 5.6.7.8 to the server
Is it even possible to solve that issue in Java or do I have to do network voodoo on the router to achieve this?
Edit: to make things clear. I know what a network proxy is and what a router does. I also know how to solve my problem on a network level using advanced network voodoo if required. What I want to know is if my guess that the problem can't be solved using Java is correct. So the bottom line question is: can I use Java to send traffic using a specific network interface to which a specific IP has been assigned or do I have to rely on what the operating system does to route my traffic (in which case the advanced network voodoo would be required)?
Edit2: If routing of network traffic can be done in java, I'd just like a quick pointer where to look into. My own googling didn't return any useful results.
1) You already have some implementations for tcp tunelling with java. Below are some examples:
http://jtcpfwd.sourceforge.net/
http://sourceforge.net/projects/jttt/
2) Even with these existing implementations, you can still do you own by forwarding packets arriving in the proxy using java.net.Socket.
3) I still think that a better option would be a specific implementation using java.lang.Runtime.exec() and socat linux command. socat is just like the Netcat but with security and chrooting support and works over various protocols and through a files, pipes, devices, TCP sockets, Unix sockets, a client for SOCKS4, proxy CONNECT, or SSL etc. To redirect all port 80 conenctions to ip 202.54.1.5:
$ socat TCP-LISTEN:80,fork TCP:202.54.1.5:80
I'm starting a new project where I need to send data from an Arduino to a Java Server. I would like to use the Arduino Wifi shield. Afterwards the java server will send the received data to a web service trough a 3G Router.
Is this setup possible? Does there exist an API to set up a socket connection between an Arduino and a Java Server?
If not which possibilities do i have? Thank in advanced
There is certainly a number of ways you can do this. You can use the Arduino Ethernet library to make connections to your Java server. Here's a nice little program called ClientConnect which uses the ethernet device to make a connection to a server. This little program sends a web request to the server with the following lines:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
On the server side it would be easiest to use some sort of simple servlet and utilize a Java web framework such as Tomcat.
Your Arduino transactions would then just look like simple web transactions:
GET /your-path-to-your-servley?field1=value1&field2=value2 HTTP/1.0
[[ empty line here ]]
This will send a set of field/value pairs to your Java webserver which will call your servlet. In the example at the top, "q" is the field name and "arduino" is the value.
Hope this helps.
Similar to the answer by #gray which is a "push" solution, is to have the java server query the Arduino at some interval ("pull" model). To do this, just see the Web hosting example in Arduino's ethernet samnple library. You can modify it, to have the arduino return the value of its sensors as part of its http response.