[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: debian and suns vm's





On Wed, 2002-06-26 at 17:27, Alex Lau wrote:
> What's the problem?


Well, 
I am afraid I can not really put the finger on the exact problem.  But I
will give here a more detailed description.  Also I will attach two
classes that both set up DatagramSockets.  

I know that this mailinglist is not about debugging Java programs but
the code is correct (I purport) and it only gives trouble on Debian,
that is why I hope somebody on this list has an idea.

Both of them work just fine on my Debian (woody) system on a IBM 1.3.x
Runtime Environment.  On Debian(woody) with a SUN Runtime Environment >=
1.3.0 only HL_WON_Connection.java works as is should.  The other one
does not throw errors, which is good so far, but it is not able to
receive answers from other servers.  The connections just time out.  

A packet sniffer told me that the packets are being sent correctly, but
there are no response packages 8( . 

On any other linux I have a hand on (linuxfromscratch and some redhat
version) I could not find any problem with SUN's VMs and this code.

Also, I do not have many Debian systems (only one) to test the code, I
would be happy if someone has the time to test the code on his/her
Debain system and see if it works.  The problem might just exist on my
machine 8( .

Thanks,
Thorsten.

A compilable version can be found at:
http://sourceforge.net/project/showfiles.php?group_id=45431
if you downloaded a serverlist and started to ping and the table stays
empty, there is no response.
(NOTE: please don't get me wrong, this is NO promotion campaign)

> 
> wolpers :
> 
> >Hello,
> >
> >I was wondering if anybody else but me has problems with DatagramSockets
> >on Debian Woody in conjunction with SUNs virtual machines version 1.3
> >and up.  The ones from IBM seem to work quite fine on my system.
> >
> >The thing is I get no exeptions and no response when I try to
> >communicate with some servers.  Again, the same code on IBMs vm works as
> >a treat.
> >
> >Thorsten
> >
> >
> >
> >
> >
> >  
> >
> 
> 
> 

/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/
    
/*
 * HL_WON_Connection.java
 *
 * Created on December 16, 2001, 2:30 PM
 */

package searchtool.halflife.protocol;


import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import java.text.*;
/**
 *
 * @author  zoidberg
 * @version
 */
public class HL_WON_Connection extends Thread{
private DatagramSocket socket = null;
    private DatagramPacket snd_packet = null;
    private DatagramPacket get_packet = null;
    private InetAddress inet_address = null;
    private int port;
    private byte[] sndbyte;
    private byte[] getbyte = new byte[2048];
    private String command,ip;
    private static int final_server_count = -1;
    private static Vector static_server_vector = null;
    private static int servercount = 0;
    private static boolean finished = false;

    private static Vector servervector = new Vector();
    /** Creates new HL_WON_Connection */

    public HL_WON_Connection(String IP, int Port) {
        ip = IP;
        port = Port;
    }
    public static void clearServervector(){
        servervector = new Vector();
    }
    public static Vector getServervector(){
        return servervector;
    }

    public int[] receive(int[] position,String filter){
        try{
            inet_address = InetAddress.getByName(ip);
            socket = new DatagramSocket();
        }catch(Exception e){
            e.printStackTrace();
        }
        ByteArrayOutputStream byteout = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(byteout);
        try{
            out.writeByte((byte)'1'); // do not use the 'c' character here
            // caused only trouble for me. (event though it is mentioned in the
            // half-life SDK to use the 'c'.  '1' isn't mentioned there)
            for(int i = 0; i < 4; i++)
                out.writeByte(position[i]);
            out.writeBytes(filter);
            out.close();
            byteout.close();
            sndbyte = byteout.toByteArray();

        }catch(Exception f){
            f.printStackTrace();
        }
        snd_packet = new DatagramPacket(sndbyte,sndbyte.length,inet_address,port);
        get_packet = new DatagramPacket(getbyte,getbyte.length);
        try{
            socket.send(snd_packet);
            socket.setSoTimeout(2000);
            socket.receive(get_packet);
            socket.close();
        }catch(InterruptedIOException x){
            final_server_count = -2;
            return position;
        }catch(Exception e){
            e.printStackTrace();
            final_server_count = -2;
            return new int[]{0,0,0,0};
        }
        try{
            ByteArrayInputStream bytein = new ByteArrayInputStream(getbyte);
            DataInputStream in = new DataInputStream(bytein);
            String result = "\nget:";
            result+=" "+in.readUnsignedByte();
            result+=" "+in.readUnsignedByte();
            result+=" "+in.readUnsignedByte();
            result+=" "+in.readUnsignedByte();
            result+=" "+(char)in.readUnsignedByte();
            result+=" "+in.readUnsignedByte();
            for(int i = 0; i < 4; i++)
                position[i] = in.readUnsignedByte();

            while(true){
                String ip = "";
                ip = ip + (in.readUnsignedByte());
                if(ip.equals("0")){
                    break;
                }
                ip = ip + "."+(in.readUnsignedByte());
                ip = ip + "."+(in.readUnsignedByte());
                ip = ip + "."+(in.readUnsignedByte());
                port = in.readUnsignedShort();
                //ControlMasterQ.addServerInfo(new ServerInfo(ip,port));
                //servervector.addElement(new ServerInfo(ip,port));
                servervector.addElement(ip + " " + port);
                servercount++;
                //System.out.println(ip+" "+port);
            }
            in.close();
            bytein.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return position;
    }
}
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/
    
/*
 * HL_Connection.java
 *
 * Created on December 16, 2001, 2:16 PM
 */

package searchtool.halflife.protocol;

import searchtool.interfaces.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import java.text.*;
/** use this to receive an udp-byte package from the server
 *  by giving the serveraddress and the command as an argument.
 *
 * the receive method returns false if something went wrong
 * (connection problem , wrong command, etc. )
 *
 *
 * @author  zoidberg
 * @version
 */
public class HL_Connection {
    private DatagramSocket socket = null;
    private DatagramPacket snd_packet = null;
    private DatagramPacket get_packet = null;
    private InetAddress inet_address = null;
    private int port;
    private byte[] sndbyte;
    private byte[] getbyte = new byte[5000];
    private String command,ip;
    /** Creates new HL_Connection */
    public HL_Connection(String IP, int Port, String Command) {
        ip = IP;
        port = Port;
        command = Command;
    }
    
    public boolean receive(){
        try{
            inet_address = InetAddress.getByName(ip);
            socket = new DatagramSocket();
        }catch(Exception e){
            e.printStackTrace();
        }
        String query_string = "\377"+"\377"+"\377"+"\377"+command+"\0";
        sndbyte = query_string.getBytes();
        snd_packet = new DatagramPacket(sndbyte,sndbyte.length,inet_address,port);
        get_packet = new DatagramPacket(getbyte,getbyte.length);
        try{
            socket.send(snd_packet);
            socket.setSoTimeout(2000);
            socket.receive(get_packet);
            socket.close();
        }catch(InterruptedIOException x){
            socket.close();
            return false; // timeout
        }catch(SocketException y){
            //y.printStackTrace();
            ;// hmm, not nice.  but cant help it.
        }catch(IOException ignored){
            socket.close();
            return false;
        }
        return true;
    }
    
    public byte[] getBytes(){
        return getbyte;
    }
}

Reply to: