Tutorial by Examples

Server: Start, and wait for incoming connections //Open a listening "ServerSocket" on port 1234. ServerSocket serverSocket = new ServerSocket(1234); while (true) { // Wait for a client connection. // Once a client connected, we get a "Socket" object // that c...
public class TrustLoader { public static void main(String args[]) { try { //Gets the inputstream of a a trust store file under ssl/rpgrenadesClient.jks //This path refers to the ssl folder in the jar file, in a jar file in the same directory ...
import java.io.*; import java.net.Socket; public class Main { public static void main(String[] args) throws IOException {//We don't handle Exceptions in this example //Open a socket to stackoverflow.com, port 80 Socket socket = new Socket("stackoverflow.com",8...
Client.java import java.io.*; import java.net.*; public class Client{ public static void main(String [] args) throws IOException{ DatagramSocket clientSocket = new DatagramSocket(); InetAddress address = InetAddress.getByName(args[0]); String ex = "He...
Multicasting is a type of Datagram Socket. Unlike regular Datagrams, Multicasting doesn't handle each client individually instead it sends it out to one IP Address and all subscribed clients will get the message. Example code for a server side: public class Server { private DatagramSo...
Sometimes in a development or testing environment, the SSL certificate chain might not have been fully established (yet). To continue developing and testing, you can turn off SSL verification programmatically by installing an "all-trusting" trust manager: try { // Create a trust mana...
If the file already exists, it will be overwritten! String fileName = "file.zip"; // name of the file String urlToGetFrom = "http://www.mywebsite.com/"; // URL to get it from String pathToSaveTo = "C:\\Users\\user\\"; // where to put it ...

Page 1 of 1