The code is a simple program to send stuff from one computer to the other. It works if the client and server are connected to different networks, but won't work when its the same network. (port forwarding is enabled for all the ports in use)
This is for a different program which works kinda like a blockchain. I'm not sure if its a router problem. My guess is that the port forwarding won't work internally between the network clients, which would seem like a router problem. HELP!
Client Side:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception{
String ipaddress = "70.121.56.92";
DatagramSocket reciever = new DatagramSocket(3535);
DatagramPacket pacc = new DatagramPacket(new byte[98],98);
Scanner s = new Scanner(System.in);
if (s.nextLine().equals("0")) {
reciever.receive(pacc);
System.out.println(Arrays.toString(pacc.getData()));
}
}
}
Server Side:
import java.net.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception{
Scanner kb=new Scanner(System.in);
DatagramSocket me=new DatagramSocket(3537);
String msg="";
while(!msg.equals("stop")){
System.out.print("msg: ");
msg=kb.nextLine();
byte[] bs=new byte[msg.length()];
for(int i=0; i <msg.length(); ++i){
bs[i] = (byte) msg.charAt(i);
}
DatagramPacket dgp=new DatagramPacket(bs, bs.length, InetAddress.getByName("70.121.**.9*"//this is my public router address), 3535 );
me.send(dgp);
}
}
}
On a different network it shows the string i put in the client on the server console. On the same network, it gets stuck inside the reciever.recieve() method