title: How SignalR works internally: client side
body: <p>I'm writing my own SignalR Client on Java and I'm facing some troubles.</p>
  
  <p>At first I want to implement PersistentConnection logic. My server code is taken from example:</p>
  
  <pre><code>public class Battle : PersistentConnection
  {
      protected override Task OnConnectedAsync(IRequest request, string connectionId)
      {
          return Connection.Broadcast("Connection " + connectionId + " connected");
      }
  
      protected override Task OnReconnectedAsync(IRequest request, IEnumerable&lt;string&gt; groups, string clientId)
      {
          return Connection.Broadcast("Client " + clientId + " re-connected");
      }
  
      protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
      {
          // return Connection.Broadcast("Connection " + connectionId + " sent ");
          return Connection.Send(connectionId, "Connection " + connectionId + " sent ");  
      }
  
      protected override Task OnDisconnectAsync(string connectionId)
      {
          return Connection.Broadcast("Connection " + connectionId + " disconncted");
      }
  
      protected override Task OnErrorAsync(Exception error)
      {
          return Connection.Broadcast("Error occured " + error);
      }
  }
  </code></pre>
  
  <p>Judging by .NET client code, I understood that in order to connect to server client should:</p>
  
  <p>1) Send request to <code>http://myserver/battle/negotiate</code> and get <code>ConnectionId</code> from response</p>
  
  <p>2) Send request to <code>http://myserver/battle/connect?transport=longPolling&amp;connectionId=&lt;received_connection_id&gt;</code></p>
  
  <p>My question is waht should client do to maintain connection? How should it listen to server broadcasting messages?</p>
  
  <p>Another issue is that I receive no response when I'm trying to send message from client to server after connection has been established. I send request to <code>http://myserver/battle/send?transport=longPolling&amp;connectionId=&lt;received_connection_id&gt;</code>. Method <code>OnReceivedAsync</code> is always called, but I get no response (independently of data sent).</p>
  
  <p>I'd be grateful for any explanations on my questions and on internal principles of SignalR work. 
  Thanks in advance.</p>