Redirecting TCP traffic to another destination - java

I have a game client. Which connects to this game.
I'm trying to set up a socket server which intercepts all traffic to the game server(The game runs through the use of sockets)
My problem is that i would need to redirect all traffic my computer makes to the game servers ip + port to 127.0.0.1 to make it connect to the socket server i've made myself first.
I know i could use the windows hosts file but this redirects ALL traffic. I only want 1 port redirected(The one with TCP traffic) If the HTTP traffic also gets redirected it ruins everything.
I'm using windows 7

Maybe Privoxy can help you. It's a successor of Internet Junkbuster, as mentioned in the answer for the following question.

Related

Public to Local IP Communication

I have created project which has two components as Desktop client and web.
web server is communicating to the my another program which i run as client on other systems.
After connecting those clients communication is happening in network as all IP's within network are reachable.
However, when i deployed web app on public IP now i am not able to connect the clients as the local IP's of those clients are not reachable by server.
How can i achieve this communication between local IP to public and vice versa?
There are multiple ways to achieve this.
Anyways, if you want the service to be reachable publically then you´ll probalby want to forward the Port to the machine running the service.
Also, make sure the Firewall allows connections to this port.
Since you´re talking about Web-Apps it´s probably HTTP, Port 80 TCP, or HTTPS, the encrypted version of HTTP running on port 443 TCP.
To explain it, your ISP gives you one public IP address.
Since you probably have multiple devices using internet, they all appear in the internet as the one IP address your provider gave you.
Whenever you send something out your router will remember where you tried to connect and if a response comes in your router knows which device to send the response to.
Now, since you want someone to connect to you, there was no request so your router does not know where to put the packet and simply blocks it.
In most routers you can configure something usually called NAT or Port Forwarding. You simply specify that communication on Port 80 or 443 should be routed to the internal IP. It has one of the following formats:
192.168.0.1 - 192.168.255.254
172.16.XXX.XXX - 172.31.255.254
10.0.0.0 – 10.255.255.254

Which things should be taken care of in Java Socket Application over DDNS?

I have developed a Chat Application for two person, one being server another will be client, using Java Socket Programming. Every thing was fine till this morning. It was working over localhost, local networks as well as On my DDNS ( My Router is configured to forward any traffic on it's port 8888 and 3434 to same port on my IP, which is again Reserved in my router ). But now it works strangely. I ran a server on my laptop at port 8888 I tried to connect the client through my DDNS on port 8888, Client shows it is connected, but Server shows it is disconnected. Client even sends message successfully which does not appear in server.
I want to know what causes such strange behaviour of my application, is this my firewall, because I have used my DDNS a lot in order to debug some issue.
I also want to know what precautions should one take in order to use DDNS in Java Socket.
Additional Informations:
My DDNS in on Dynu
OS: Windows 7 32 bit
Quick Heal Antivirus and firewall (Outdated)
I am adding some pictures:

Get Port of Incoming Request - App Engine, Java

I have an application running on Google App Engine and a client connects to the server at a specific URL performing an HTTP POST (or GET or whatever) request. My question is simple: how would I go about obtaining the client's port?
Thankyou for any help anyone here can provide!
--- Additional Info ---
Note that in most cases 'Client's port' = a translated port that the Client's Modem's NAT set. If a NAT is present, I do not require the client's local port on their computer that they are using to hit the server, for this is of little use to me. Instead, I require the port from the Modem's public IP that will redirect the request to my original client.
I need this info to send more data to the client (through sockets) at some later point in time. Straight after its initial post request, the original client creates a server socket that listens for requests from the server. The server is only able to send requests to the client if it knows the ip:port of the client.
I am aware of the issue request below. It is 3.5 years old though, and still no action has been taken - it will never be fixed. I was hoping that someone here might know of a workaround.
https://code.google.com/p/googleappengine/issues/detail?id=4210&q=Type%3DDefect&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log&start=100
Afaik, the info on remote TCP port is not available via GAE APIs.
Most of the time clients are behind NAT so they are not accessible from internet, i.e. even if the have a listening port open, you can not Make a TCP connection to it due to one-way nature of NAT translation.
If a client has a public IP, then they can just simply tell server on which port they will be listening and you can then use URL Fetch or Outgoing Sockets to make a connection.

Java nat traversal for chat application

I am trying to create a java chat application for my networking class. As of right now I am stuck trying to connect to someone behind a different router. The way I have my project right now is I have a client program and a server program. The client programs first logs into the server program which logs their IP and port in a database and then the server gives them back the list of their friends with their IPs and ports. Then the client closes down the connection to the server and tries to connect to another client using the information the server sent back. So far my program only works connecting to the server and getting the friends IP and port but when I use those values to connect to the other client I cant connect.
socket = new Socket();
socket.setReuseAddress(true);
socket.setKeepAlive(true);
socket.setSoLinger(true, 10);
socket.bind(new InetSocketAddress(Port));
socket.connect(new InetSocketAddress(host, SERVER_PORT));
reusePort = socket.getLocalPort();
Above is a snippet of java code used to connect to the server then below is what i do on the client side.
ss = new ServerSocket(reusePort);
So now technically I am listening on the same port I used to connect to the server with which is logged in and is retrievable to another client and is in the NAT table with my ip and port. I am not sure what I am missing or if there is some protocol or something that I have to do. I have looked at TCP and UDP hole punching but I am not sure how that is actually accomplished or how to implement it.
Any suggestions would be appreciated.
If you want to send a message you'll need to set up port forwarding on any device that acts as a server (any device which creates a socket server). Port forwarding is done on the Router. The reason you cannot connect to the other client is because they are hidden behind their routers firewall. Their address to the rest of the world is actually the address of the router, not of their physical computer. On their local network they have a different address then what the rest of the world sees, and the router figures out what messages from the outside world need to be sent to the client based on an address translation table.
Given your architecture, this would mean that all clients need to have their routers doing port forwarding, which is of course unfeasible (imagine gtalk or aim requiring users to do port forwarding).
The more common architecture is to have the Server do the work of rebroadcasting messages to the connected clients and maintain tables to lookup whose talking with who. This way there is a single server which will need a static ip (or be port forwarded), and all users are simply clients which connect to the server socket and read messages from it.
For actual code describing the second architecture please see http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html. Then the machine which is running the server code either needs a static ip or if it is behind a router needs traffic from the port it is listening on to be forwarded.
So on the server code you will bind to the ip assigned from your router (something like 192.168.1.2 at some port say 5000). Then go to your routers configuration page (it may be 192.168.1.1 see http://www.wikihow.com/Port-Forward/Open-Ports-on-a-Linksys-Router), and forward port 5000 to the address 192.168.1.2.
The Interactive Connectivity Establishment (ICE) protocol combines various NAT traversal utilities such as the STUN and TURN protocols in order to offer a powerful mechanism that allows Offer/Answer based protocols such as SIP and XMPP to traverse NATs.
This project provides a Java implementation of the ICE protocol that would be usable by both SIP and XMPP applications. The project also provides features such as socket sharing and support for Pseudo TCP.
ice4j is maintained by the Jitsi community.
ice4j

Trouble connecting to other PC's TCP socket server

Me and my friend are working on online game project and for beginning we use TCP connection made by java. What do I have to do to successfuly make my friends client connect to my server? On local host it works perfectly. What are the reqiurements for this?
Check to make sure that your firewall allows connections from remote hosts to your computer on the port you are hosting the game on. If you friend is connecting to your computer from another location you will most likely need to add a firewall rule to your router.

Categories

Resources