How to specify which TCP protocol (HTTP,FTP,...) Java sockets use? - java

How do Java sockets understand that they must use FTP or HTTP or other TCP/IP protocols? Is there any specific socket method for any protocol?

How Java sockets understand that they must use FTP or HTTP or other TCP/IP protocols?
They don't. They use the TCP protocol. Application protocols such as FTP or HTTP are implemented over sockets, by the application, usually via a protocol-specific library.
Is there any specific socket method for any protocol?
I've tried but I cannot ascribe any cogent meaning to this question.

Related

Can I invoke a client´s method from a server with RMI

I would like to know if with RMI a server can remotely invoke a method from any of his clients, or just the clients can do this with their server.
Regardless of any implications of such a design decision, it is possible to use RMI between two JVMs that are accessible through the network. This means that if the server can access its clients through the network, and the clients have a JVM available and can act as RMI servers, then it is possible to make a client or each of the clients an RMI server and have the "server" communicate with each one of them.
Assuming the server is an application server i advise you to use the Java Messaging Service (JMS) to allow the server communicate with the client systems.
Yes, firewalls permitting. The client has to export its callbacks as remote objects and supply them to the server, typically via some registerCallback() API. Then the server just calls the methods.
However firewalls to the Internet typically don't permit callbacks, and if they do there may be issues with port numbers: you will probably need the clients to export their remote objects on a specific port which is opened in the firewall, typically 1099.
Besides the solution provided by melc, it is also possible to achieve a full duplex communication between the client and server by using WebSockets. They are now part of the Java EE 7 specification, you can read something more about them here: http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm. There are also other solutions, like Comet, or JMS (which is used like webosckets in RichFaces).

Protocol for device tracking

I want to create a server through which i can track devices(mobile,vechile etc etc).
How can i create a protocol that can accept commands from all type of devices.
The simplest solution is to support TCP or UDP requests assuming they support IP. I would suggest getting TCP to work first. I would send what you need to send in the simplest Text or Binary format you can come up with.
If they don't support IP I suggest creating a gateway which support the transport they support already and pass this to TCP so your server has a common transport and protocol to talk to.

Client-Server Communication (without port forwarding) when both are behind routers

hi
I have a client and server both of which are behind routers. They need to communicate over sockets. Enabling port-forwarding is not an option.
The client-server will maintain a live socket connection and the server will notify the client when an event occurs. Polling as an alternative for the client is not an option.
I am using plain-java.
How do I go about doing this?
Regards
Chimanrao
You may try to use UPnP. That is about the only option if you do not have a server outside of the NAT.

Java: DatagramSocket and proxy (firewall)

It may be that I'm not understanding the UDP protocol...
I'm trying to receive data from a server using the UDP protocol, but I'm sitting behind a firewall. The URLConnection constructor can take an instance of Proxy (as well as a way to set up user name and password of such a proxy server).
How do I connect through a proxy server using the UDP protocol (DatagramSocket)?
Best regards,
TX
Most Proxy servers support the HTTP protocol which is TCP based, so you don't have to do anything with the proxy server to do this.
To pass UDP over a proxy server, you need a proxy which supports UDP. I don't know of any proxy server which supports this so you may have to write one yourself. It is worth noting that UDP is a connectionless protocol which means you have have to authenticate every packet.
SOCKS5, which is an extension of SOCKS4, includes support for UDP in addition to authentication. One implementation of a SOCKS5 Server written in Java is JSOCKS. You can check this project out at http://jsocks.sourceforge.net/.
Refer to RFC 1928 (https://www.rfc-editor.org/rfc/rfc1928) for more information on SOCKS5.

Using FTP Proxy with apache commons-net

I want to set up an FTP connection using a proxy server with Apache's commons-net.
But looking at this Does FTPClient support FTP connections through an FTP proxy server? has me worried.
I have to meddle with the system properties and the Sun docs state that "If socksProxyHost is specified then all TCP sockets will use the SOCKS proxy server to establish a connection or accept one."
WTH? All TCP sockets? What about my database connections? Or other FTP connections i might want to open at the same time not using a proxy? Will they all be affected?
Is there some other way to do it that doesn't mess with the rest of my application?
You have several ways of using proxies in Java, especially from version 1.5.
Using System Properties: quick & powerfull but limited flexibility
You can use use a SOCKS proxy for all TCP connections.
You can also set a proxy per protocol, doable for HTTP, FTP and HTTPS
For both methods, you can specify a list of hosts that will not use proxy
Using the java.net.Proxy class (Java 1.5+) to set (or not) a Proxy per Connection
Impleting a java.net.ProxySelector (idem) which will determine a Proxy for each Connection according to your criteria
See the detailled Sun technote on networking & proxies.

Categories

Resources