marwan Posted August 23, 2013 Author Posted August 23, 2013 Wouldn't it be better with sockets? I used to face problems trading datagram packets between machines who belong to different networks. choose DatagramSockets because Sockets had a limitation in connection(only 1 client can connect) because of streams
Pauler Posted August 23, 2013 Posted August 23, 2013 choose DatagramSockets because Sockets had a limitation in connection(only 1 client can connect) because of streams In combination with threads you can connect to multiple clients. But, in this occasions, it seems that Datagrams are fine, by the time packet order doesn't matter. Also, you propably forgot to send the online data back to the client, at the online command.
marwan Posted August 23, 2013 Author Posted August 23, 2013 In combination with threads you can connect to multiple clients. But, in this occasions, it seems that Datagrams are fine, by the time packet order doesn't matter. I was afraid of packet loss/order but most of people going to use it through localhost and if machine I think machine have connection speed enough to send and recieve data without any problems. Also, you propably forgot to send the online data back to the client, at the online command. updated thanks
Setekh Posted August 23, 2013 Posted August 23, 2013 U guys suck at channels and threading. Datagram = (unreliable connection - that's its naming, but its a good thing!) simple minded. Connection - W <-> R, end; Perfect for telnets. Or command servers. TCP = (Transport Protocol) bad for such a thing, you need to maintain a connection, that is always vulnerable. You guys should check out SocketChannels and Datagram channels in the nio package. Edit: Dat http://docs.oracle.com/javase/7/docs/api/java/nio/channels/package-summary.html
Pauler Posted August 23, 2013 Posted August 23, 2013 Also, you MUST add some more server-side checks about the password, because in that way if someone codes his own gui, which doesn't ask for a password, he would be able to send commands normally. A good idea is that after password check, the server should accept packets only by the approved ip address.
marwan Posted August 23, 2013 Author Posted August 23, 2013 Also, you MUST add some more server-side checks about the password, because in that way if someone codes his own gui, which doesn't ask for a password, he would be able to send commands normally. A good idea is that after password check, the server should accept packets only by the approved ip address. Just a boolean in server-side code.
Pauler Posted August 23, 2013 Posted August 23, 2013 Sorry, for keep messing with this one, but you reminded me to add a telnet system to pes, and while I was working on it I also realised that your client is not working too. But, the sample client that I coded worked fine. telnet package com.pauler; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; public class TelnetClient { DatagramSocket socket; public TelnetClient() { while (true) { try { socket = new DatagramSocket(); } catch (SocketException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { sendData("wswsws".getBytes(), InetAddress.getByName("127.0.0.1"), 1234); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) { getInstance(); } public static TelnetClient getInstance() { return SingletonHandler._instance; } public void sendData(byte[] data, InetAddress ipAddress, int packetPort) { DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, packetPort); try { socket.send(packet); } catch (IOException e) { e.printStackTrace(); } System.out.println("sent : " + new String(data)); } private static class SingletonHandler { protected static final TelnetClient _instance = new TelnetClient(); } }
marwan Posted August 23, 2013 Author Posted August 23, 2013 Sorry, for keep messing with this one, but you reminded me to add a telnet system to pes, and while I was working on it I also realised that your client is not working too. But, the sample client that I coded worked fine. telnet package com.pauler; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; public class TelnetClient { DatagramSocket socket; public TelnetClient() { while (true) { try { socket = new DatagramSocket(); } catch (SocketException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { sendData("wswsws".getBytes(), InetAddress.getByName("127.0.0.1"), 1234); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) { getInstance(); } public static TelnetClient getInstance() { return SingletonHandler._instance; } public void sendData(byte[] data, InetAddress ipAddress, int packetPort) { DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, packetPort); try { socket.send(packet); } catch (IOException e) { e.printStackTrace(); } System.out.println("sent : " + new String(data)); } private static class SingletonHandler { protected static final TelnetClient _instance = new TelnetClient(); } } Damn, forgot to add port when you connect . im fking idiot so the jar was sending to other port this is why the server didn't respond. Updated the jar download : http://www.4shared.com/file/jMwT12D0/Telnet.html code : http://pastebin.com/gcH4J8Xz Also added a boolean check if connected to be more secured really sorry i dont know how i forgot to add the port
FirefoxAurora Posted August 23, 2013 Posted August 23, 2013 Thanks for share :) for sure am gonna use it :D maybe not for l2 but for sure you gave enough ideas :)
Pauler Posted August 23, 2013 Posted August 23, 2013 Damn, forgot to add port when you connect . im fking idiot so the jar was sending to other port this is why the server didn't respond. Updated the jar download : http://www.4shared.com/file/jMwT12D0/Telnet.html code : http://pastebin.com/gcH4J8Xz Also added a boolean check if connected to be more secured really sorry i dont know how i forgot to add the port Again, it is not secured. Once it gets to true, everyone would be able to connect by a custom client.
marwan Posted August 23, 2013 Author Posted August 23, 2013 Again, it is not secured. Once it gets to true, everyone would be able to connect by a custom client. So only 1 connection to server ? added video
Pauler Posted August 24, 2013 Posted August 24, 2013 https://xp-dev.com/trac/l2jpes/browser/l2jpes/trunk/interlude/gameserver/java/com/l2jpes/Telnet.java?rev=45
marwan Posted August 24, 2013 Author Posted August 24, 2013 https://xp-dev.com/trac/l2jpes/browser/l2jpes/trunk/interlude/gameserver/java/com/l2jpes/Telnet.java?rev=45 Addding ip's to List not bad You should also add command like "exit" or something so it removes ip from the List . But not that important
Recommended Posts