Jump to content

Recommended Posts

Posted

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 

Posted

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.

Posted

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

Posted

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

Posted

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.

Posted

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.

Posted

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();
}
}

 

 

Posted

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

bq8s.png

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

 

Posted

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

bq8s.png

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.
Posted

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

 

Guest
This topic is now closed to further replies.
×
×
  • Create New...