diff --git a/src/java/com/threerings/presents/client/BlockingCommunicator.java b/src/java/com/threerings/presents/client/BlockingCommunicator.java index d4b35415c..d7c41697c 100644 --- a/src/java/com/threerings/presents/client/BlockingCommunicator.java +++ b/src/java/com/threerings/presents/client/BlockingCommunicator.java @@ -56,6 +56,7 @@ import com.threerings.presents.net.AuthResponseData; import com.threerings.presents.net.DownstreamMessage; import com.threerings.presents.net.LogoffRequest; import com.threerings.presents.net.PingRequest; +import com.threerings.presents.net.TransmitDatagramsRequest; import com.threerings.presents.net.Transport; import com.threerings.presents.net.UpstreamMessage; import com.threerings.presents.util.DatagramSequencer; @@ -766,6 +767,9 @@ public class BlockingCommunicator extends Communicator if (cport > 0) { log.info("Datagram connection established", "port", cport); + // notify the server + postMessage(new TransmitDatagramsRequest()); + // start up the writer thread _datagramWriter = new DatagramWriter(); _datagramWriter.start(); diff --git a/src/java/com/threerings/presents/net/TransmitDatagramsRequest.java b/src/java/com/threerings/presents/net/TransmitDatagramsRequest.java new file mode 100644 index 000000000..05e3321d4 --- /dev/null +++ b/src/java/com/threerings/presents/net/TransmitDatagramsRequest.java @@ -0,0 +1,34 @@ +// +// $Id$ +// +// Narya library - tools for developing networked games +// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/narya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.presents.net; + +/** + * Notifies the server that we would like it to send us datagrams. + */ +public class TransmitDatagramsRequest extends UpstreamMessage +{ + @Override + public String toString () + { + return "[type=TRANSMIT_DATAGRAMS, msgid=" + messageId + "]"; + } +} diff --git a/src/java/com/threerings/presents/server/PresentsSession.java b/src/java/com/threerings/presents/server/PresentsSession.java index f9b1ba17a..10561c895 100644 --- a/src/java/com/threerings/presents/server/PresentsSession.java +++ b/src/java/com/threerings/presents/server/PresentsSession.java @@ -63,6 +63,7 @@ import com.threerings.presents.net.PingRequest; import com.threerings.presents.net.PongResponse; import com.threerings.presents.net.SubscribeRequest; import com.threerings.presents.net.ThrottleUpdatedMessage; +import com.threerings.presents.net.TransmitDatagramsRequest; import com.threerings.presents.net.UnsubscribeRequest; import com.threerings.presents.net.UnsubscribeResponse; import com.threerings.presents.net.UpdateThrottleMessage; @@ -1085,6 +1086,18 @@ public class PresentsSession } } + /** + * Processes datagram transmission requests. + */ + protected static class TransmitDatagramsDispatcher implements MessageDispatcher + { + public void dispatch (PresentsSession client, Message msg) + { + log.debug("Client requested datagram transmission", "client", client); + client.getConnection().setTransmitDatagrams(true); + } + } + /** * Processes throttle updated messages. */ @@ -1158,6 +1171,7 @@ public class PresentsSession _disps.put(UnsubscribeRequest.class, new UnsubscribeDispatcher()); _disps.put(ForwardEventRequest.class, new ForwardEventDispatcher()); _disps.put(PingRequest.class, new PingDispatcher()); + _disps.put(TransmitDatagramsRequest.class, new TransmitDatagramsDispatcher()); _disps.put(ThrottleUpdatedMessage.class, new ThrottleUpdatedDispatcher()); _disps.put(LogoffRequest.class, new LogoffDispatcher()); } diff --git a/src/java/com/threerings/presents/server/net/Connection.java b/src/java/com/threerings/presents/server/net/Connection.java index 3f760cfa0..97a30b56d 100644 --- a/src/java/com/threerings/presents/server/net/Connection.java +++ b/src/java/com/threerings/presents/server/net/Connection.java @@ -121,6 +121,22 @@ public class Connection implements NetEventHandler return (_channel == null) ? null : _channel.socket().getInetAddress(); } + /** + * Sets whether we should transmit datagrams. + */ + public void setTransmitDatagrams (boolean transmit) + { + _transmitDatagrams = transmit; + } + + /** + * Checks whether we should transmit datagrams. + */ + public boolean getTransmitDatagrams () + { + return _transmitDatagrams; + } + /** * Returns the address to which datagrams should be sent or null if no datagram address has * been established. @@ -435,6 +451,7 @@ public class Connection implements NetEventHandler protected InetSocketAddress _datagramAddress; protected byte[] _datagramSecret; + protected boolean _transmitDatagrams; protected MessageDigest _digest; protected DatagramSequencer _sequencer; diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index 0d2d378bc..08a39d71c 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -61,6 +61,7 @@ import com.threerings.presents.annotation.AuthInvoker; import com.threerings.presents.client.Client; import com.threerings.presents.data.ConMgrStats; import com.threerings.presents.net.Message; +import com.threerings.presents.net.PongResponse; import com.threerings.presents.server.Authenticator; import com.threerings.presents.server.ChainedAuthenticator; import com.threerings.presents.server.ClientManager; @@ -902,9 +903,11 @@ public class ConnectionManager extends LoopingThread } try { - // send it as a datagram if hinted and possible - if (!msg.getTransport().isReliable() && conn.getDatagramAddress() != null && - postDatagram(conn, msg)) { + // send it as a datagram if hinted and possible (pongs must be sent as part of the + // negotation process) + if (!msg.getTransport().isReliable() && + (conn.getTransmitDatagrams() || msg instanceof PongResponse) && + postDatagram(conn, msg)) { return; }