// The server delegates handling client requests to a serverConnection object. public XmlRpcServerConnection(Socket fd, XmlRpcServer server, bool deleteOnClose /*= false*/) //: base(fd, deleteOnClose) { XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.INFO, "XmlRpcServerConnection: new socket {0}.", fd.RemoteEndPoint.ToString()); this.server = server; socket = fd; stream = new NetworkStream(socket,true); _connectionState = ServerConnectionState.READ_HEADER; KeepOpen = true; _keepAlive = true; }
private void OnNewServerConnection(Socket socket) { ServerConnectionState wrapper = new ServerConnectionState(socket); lock (connectedLock) { newServersAwaitingConfirmation.Add(wrapper); } IPEndPoint remoteIpEndPoint = socket.RemoteEndPoint as IPEndPoint; Console.WriteLine("OnNewServerConnection {0}", remoteIpEndPoint.Address); NotifyEndpoint_ServerId(wrapper); }
public MainPage() { this.InitializeComponent(); m_Connection = new Connection("localhost", 7474); m_ServerConnectionState = ServerConnectionState.Disconnected; m_Controller = new Controller(m_Connection); m_StateView = new StateView(); m_StateWatcher = new StateWatcher(Dispatcher, m_StateView, m_Controller); m_ServerConnectionStateTimer = ThreadPoolTimer.CreatePeriodicTimer(ServerConnectionStateUpdate, TimeSpan.FromSeconds(1.0)); DataContext = m_StateView; }
internal override bool readHeader(ref HTTPHeader header) { if (base.readHeader(ref header)) { if (header.m_headerStatus == HTTPHeader.STATUS.COMPLETE_HEADER) { XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "KeepAlive: {0}", _keepAlive); _connectionState = ServerConnectionState.READ_REQUEST; } return(true); } return(false); }
internal override bool ReadHeader(ref HttpHeader header) { if (base.ReadHeader(ref header)) { if (header.HeaderStatus == HttpHeader.ParseStatus.COMPLETE_HEADER) { logger.LogDebug("KeepAlive: {0}", keepAlive); connectionState = ServerConnectionState.READ_REQUEST; } return(true); } return(false); }
internal override bool readHeader(ref HttpHeader header) { if (base.readHeader(ref header)) { if (header.HeaderStatus == HttpHeader.ParseStatus.COMPLETE_HEADER) { Debug.WriteLine("KeepAlive: {0}", _keepAlive); _connectionState = ServerConnectionState.READ_REQUEST; } return(true); } return(false); }
//===========================================================================================// private async Task ConnectToserver(Exception ex = null) { await Task.Run(async() => { while (connection.State != HubConnectionState.Connected) { await Task.Delay(2000); try { await connection.StartAsync(); } catch { } } State = ServerConnectionState.Connected; Connected(); }); }
private bool WriteResponse(string request) { string response = server.ExecuteRequest(request); if (response.Length == 0) { logger.LogError("XmlRpcServerConnection::WriteResponse: empty response."); return(false); } try { MemoryStream memstream = new MemoryStream(); using (StreamWriter writer = new StreamWriter(memstream)) { writer.Write(response); bytesWritten = response.Length; } try { var buffer = new ArraySegment <byte>(); memstream.TryGetBuffer(out buffer); stream.Write(buffer.Array, buffer.Offset, buffer.Count); } catch (Exception ex) { logger.LogError(string.Format("Exception while writing response: {0}", ex.Message)); } } catch (Exception ex) { logger.LogError("XmlRpcServerConnection::WriteResponse: write error ({0}).", ex.Message); return(false); } logger.LogDebug("XmlRpcServerConnection::WriteResponse: wrote {0} of {0} bytes.", bytesWritten, response.Length); // Prepare to read the next request if (bytesWritten == response.Length) { response = ""; connectionState = ServerConnectionState.READ_HEADER; } return(keepAlive); // Continue monitoring this source if true }
public ConnectionState GetServerConnectionState(ServerConnectionState output) { output.realUdpEnabled = false; return(m_jsClient.GetServerConnection(m_clientInstanceID)); }
public void SetState(ServerConnectionState state) { this.m_state = state; }
public ConnectionStateChangedEventArgs(ServerConnectionState state) { State = state; }
internal override bool readHeader(ref HTTPHeader header) { if (base.readHeader(ref header)) { if (header.m_headerStatus == HTTPHeader.STATUS.COMPLETE_HEADER) { XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "KeepAlive: {0}", _keepAlive); _connectionState = ServerConnectionState.READ_REQUEST; } return true; } return false; }
private bool writeResponse(string request) { string response = server.executeRequest(request); if (response.Length == 0) { XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: empty response."); return false; } try { MemoryStream memstream = new MemoryStream(); using (StreamWriter writer = new StreamWriter(memstream)) { writer.Write(response); _bytesWritten = response.Length; } try { var buffer = memstream.GetBuffer(); stream.Write(buffer, 0, buffer.Length); } catch (Exception ex) { XmlRpcUtil.error(string.Format("Exception while writing response: {0}", ex.Message)); } } catch (Exception ex) { XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: write error ({0}).", ex.Message); return false; } /*catch (Exception ex) { XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: write error ({0}).", ex.Message); return false; }*/ XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection::writeResponse: wrote {0} of {0} bytes.", _bytesWritten, response.Length); // Prepare to read the next request if (_bytesWritten == response.Length) { response = ""; _connectionState = ServerConnectionState.READ_HEADER; } return _keepAlive; // Continue monitoring this source if true }
private bool readRequest() { int left = header.ContentLength - header.DataString.Length; int dataLen = 0; if (left > 0) { byte[] data = new byte[left]; try { dataLen = stream.Read(data, 0, left); if (dataLen == 0) { XmlRpcUtil.error("XmlRpcServerConnection::readRequest: Stream was closed"); return false; } } catch (Exception ex) { XmlRpcUtil.error("XmlRpcServerConnection::readRequest: error while reading the rest of data ({0}).", ex.Message); return false; } header.Append(Encoding.ASCII.GetString(data, 0, dataLen)); } // Otherwise, parse and dispatch the request XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection::readRequest read {0} bytes.", dataLen); if (!header.ContentComplete) { return false; } _connectionState = ServerConnectionState.WRITE_RESPONSE; return true; // Continue monitoring this source }
private void ServerConnectionStateUpdate(ThreadPoolTimer source) { if (m_ServerConnectionState != m_Connection.ServerConnectionState) { m_ServerConnectionState = m_Connection.ServerConnectionState; IAsyncAction result = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { TextBlock_ServerConnectionState.Text = m_ServerConnectionState.ToString(); }); } if (m_ConnectionState != m_Connection.State) { m_ConnectionState = m_Connection.State; IAsyncAction result = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { TextBlock_PM3ConnectionState.Text = m_ConnectionState.ToString(); }); } }