Subversion Repositories programming

Rev

Rev 216 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 216 Rev 217
Line 22... Line 22...
22
    private static DatagramSocket socket;
22
    private static DatagramSocket socket;
23
    private static DatagramPacket packet;
23
    private static DatagramPacket packet;
24
    private static int portNumber = 1337;
24
    private static int portNumber = 1337;
25
    private static int packetNum = 0;
25
    private static int packetNum = 0;
26
 
26
 
-
 
27
    public static boolean verifyInput (String s)
-
 
28
    {
-
 
29
        int i;
-
 
30
        
-
 
31
        // Check for QUIT message
-
 
32
        if (s.equals("QUIT"))
-
 
33
            return true;
-
 
34
 
-
 
35
        // If it's not a QUIT, it must be 0's and 1's only
-
 
36
        for (i=0; i<s.length; i++)
-
 
37
            if (!(s.charAt(i) == '0' || s.charAt(i) == '1'))
-
 
38
                return false;
-
 
39
 
-
 
40
        // Everything was a 0 or 1, good!
-
 
41
        return true;
-
 
42
    }
-
 
43
 
27
    /**
44
    /**
28
     * Method: readPacket()
45
     * Method: readPacket()
29
     * Purpose: Read a packet on the currently opened DatagramSocket,
46
     * Purpose: Read a packet on the currently opened DatagramSocket,
30
     * and return it as a String.
47
     * and return it as a String.
31
     */
48
     */
Line 88... Line 105...
88
    }
105
    }
89
 
106
 
90
    /**
107
    /**
91
     * Method: guaranteedTransmit()
108
     * Method: guaranteedTransmit()
92
     * Purpose: A wrapper around readPacket() and writePacket() that implements
109
     * Purpose: A wrapper around readPacket() and writePacket() that implements
93
     * a reliable transmit mechanism. It allows you to specify a maximum number
-
 
94
     * of times to try resending a packet.
110
     * a reliable transmit mechanism.
95
     */
111
     */
96
    public static P2_Packet guaranteedTransmit (byte type, byte[] data)
112
    public static P2_Packet guaranteedTransmit (byte type, byte[] data)
97
    {
113
    {
98
        P2_Packet reply;
114
        P2_Packet reply;
99
        int retries = 0;
115
        int retries = 0;
Line 114... Line 130...
114
 
130
 
115
        packetNum++;
131
        packetNum++;
116
        return reply;
132
        return reply;
117
    }
133
    }
118
 
134
 
-
 
135
    /**
-
 
136
     * Method: guaranteedTransmit()
-
 
137
     * Purpose: A simplified version of the guaranteedTransmit() above.
-
 
138
     */
119
    public static P2_Packet guaranteedTransmit (byte type)
139
    public static P2_Packet guaranteedTransmit (byte type)
120
    {
140
    {
121
        byte[] pData = { 0 };
141
        byte[] pData = { 0 };
122
        
142
        
123
        return guaranteedTransmit (type, pData);
143
        return guaranteedTransmit (type, pData);