001    package org.protocol;
002    
003    import java.util.*;
004    import java.io.*;
005    import java.net.*;
006    import java.awt.*;
007    import java.awt.event.*;
008    import javax.swing.*;
009    import javax.swing.event.*;
010    
011    public class SimpleUDPServerConnection {
012    
013            private InetSocketAddress address_;
014            private DatagramPacket packet_;
015            private int port_;
016            private int timeout_;
017            private int buf_size_;
018            private ArrayList<Connection> connection_list_ = new ArrayList<Connection>();
019            
020            private ArrayList<String> received_list_ = new ArrayList<String>();
021    
022            public SimpleUDPServerConnection(DatagramPacket received_packet) throws Exception {
023                    address_ = (InetSocketAddress)received_packet.getSocketAddress();
024                    received(received_packet);
025            }
026            
027    //      public abstract void send(String message) throws Exception ;
028    
029            protected void received(DatagramPacket packet) {
030                    String message = new String(packet.getData(), 0, packet.getLength());
031                    received_list_.add(message);
032    //              System.out.println("server received message: " + message);
033            }
034            public String receive() throws Exception {
035    // <?> this block should be changed!
036                    if(received_list_.size()>0)
037                            return received_list_.get(0);
038                    else
039                            return null;
040            }
041            public InetSocketAddress getRemoteAddress() {
042                    return address_;
043            }
044    /*
045            private void init() throws Exception {
046                    byte[] buf_ = new byte[buf_size_];
047                    packet_ = new DatagramPacket(buf_, buf_.length);
048                    socket_ = new DatagramSocket(port_);
049            }
050    */
051    
052            public static void main(String[] args) throws Exception {
053            }
054    
055            public static void alert(Object message) {
056                    System.out.println(message);
057            }
058    }