I'm using vlcj to stream (RTSP) video.
The problem is I am behind a router and dd-wrt only forwards and open ports if there is an application that is listening. But, I stream video, I don't listen on ports that are streaming...
How can I get around this problem?
Everything works fine if I don't use the router and connect directly.
*info:
linksys wrt54gl
Firmware: DD-WRT v24-sp2 (10/10/09) min
RTSP uses tcp communication for session control between clients and server. So the server will have to listen for clients. The default port for RTSP is 554, however examples on VLCj use port 5555 so be advised. This port has to be forwarded by the router from the WAN address to the LAN address of the streaming server.
Please don't confuse with RTP which uses multicast instead and broadcast to the LAN broadcast address! Doing broadcast through a router is difficult as it will have to re-broadcast to WAN.
Related
I am very new to network programming, so this might be a no brainer. What I was wondering is, I know TCP requires the client to know the IP of the server. But since UDP is connectionless server, is it still required? I mean can I make my server broadcast it's IP address on a specific port ( not necessary in the same LAN , also over internet) and make the clients listen to that port for any incoming requests and find get the IP of the server once a request is received ?
You can try to send packages on specific port over the LAN. But for the Internet no.
Look into using ARP/RARP if that gives you what you need. Coming to your question
Mind you both TCP and UDP require IP addresses binding the ip address to a port is called a socket and there can be TCP and UDP with the same port no.
You can do this according to what you said but then the server needs to know the client addresses
Create a connection from server to client
Send IP address of server to client
Client send data using just received Server IP
to work around this you can use the broadcast address of the network and have the clients listen to it, just check what your broadcast address is.
What you are trying to do is similar to a DHCP server.
I want to know if there is a way to broadcast data through udp sockets for clients behind a NAT. I found many examples where the server is sending data to a multicast address and clients listen on a fixed port. But if there is a NAT between them, the packages need to be sent to different ports, depending on how the NAT has created the port translations right ? So what is the solution here ?
I want to
Recieve UDP message on device when it is connected through wi-fi
Know how to send udp message on device when it is connected to wi-fi
router as the sender on diffrent network
What i have tried
http://code.google.com/p/boxeeremote/wiki/AndroidUDP
What is working
UDP messeges are being recieved on device when it is connected
through 2g/3g data service
UDP messeges are being recieved when sender and reciever are both in
same network ( behind wi-fi router )
Any help/point in right direction is appreciated.
When the device is behind a wi-fi router, it has a private address so it isn't reachable from outside the private network, at least no without some extra work.
You need to do Hole Punching, is what applications like Skype do to receive UDP packets. Applications usually use a STUN server in order to achieve this.
The easiest alternative would be to have a server with a public address and make all the devices connect to the server with tcp/ip protocol. If you can't afford that you need to do Hole Punching.
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
I'm trying to make a client/server Java App. Both client and server will be running on the same wi-fi network. Server will be running on a specific port that client is aware of.
I am planning to send a multicast message from client through the network for that specific port to discover the server. However, I'm not too sure how I can find out which IP in my network received my message.
Do I need to create a socket on the client and listen to incoming packets once I send my multicast message in case server replies back?
Thanks in advance.
(1)server listens on a pre-arranged port
DatagramSocket s = new DatagramSocket(8888);
s.receive //(1)
s.send //(2)
(3)client sends a message to the port, on the broadcast IP, 255.255.255.255
DatagramSocket c = new DatagramSocket();
c.send(255.255.255.255:8888,msg) //(3)
c.receive //(4)
the client binds to a port too. we didn't specify it, so it's random chosen for us.
(3) will broadcast the message to all local machines, server at (1) receives message, with the client IP:port.
(2) server sends response message to client IP:port
(4) client gets the reponse message from server.
I would strongly recommend using JGroups. It has a lot of features and it will do all the UDP stuff. JBoss uses it for their clustering.
You can try using java.net.MulticastSocket (available since Java 1.1). If you don't need the rich feature sets of libs like jgroups, hazelcast etc. that plain Java API might serve you well enough.
See also example pages here and here.
You could try using SSDP. It's what UPnP devices use to discover each other. It's multicast on port 1900 and just uses really simple packets to send around IPs and service information.
Cling is a UPnP lib you can pull from. Note I'm not recommending you move to UPnP - just the discovery protocol used.