private void StartAction() { try { ActionSocket.Listen(MaxQueueLength); while (true) { Socket handler = ActionSocket.Accept(); string data = null; while (true) { Bytes = new byte[BufferSize]; int bytesRec = handler.Receive(Bytes); data += Encoding.ASCII.GetString(Bytes, 0, bytesRec); if (BufferSize > bytesRec) { break; } } EvaluateData(data); handler.Shutdown(SocketShutdown.Both); //TODO upewnic się że powininemzamykać socket handler.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void StartAction() { try { Console.WriteLine(this.PortNumber); ActionSocket.Listen(MaxQueueLength); while (true) { Socket handler = ActionSocket.Accept(); List <byte> recivedData = new List <byte>(); while (true) { Bytes = new byte[BufferSize]; int bytesRec = handler.Receive(Bytes); //data += Encoding.ASCII.GetString(Bytes, 0, bytesRec); byte[] nonNull = new byte[bytesRec]; Array.Copy(Bytes, 0, nonNull, 0, bytesRec); recivedData.AddRange(nonNull); if (BufferSize > bytesRec) { break; } } if (!Active) { continue; } InputBuffer.Add(recivedData); if (HandleIncomingData != null) { HandleIncomingData(this, EventArgs.Empty); } handler.Shutdown(SocketShutdown.Both); //TODO upewnic się że powininemzamykać socket handler.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void SendContent(string json) { try { SetSocket(); ActionSocket.Connect(ActionEndPoint); byte[] msg = Encoding.ASCII.GetBytes(json); ActionSocket.Send(msg); ActionSocket.Shutdown(SocketShutdown.Both); ActionSocket.Close(); } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); } }
public void ConnectToLocalPoint() { SetSocket(); ActionSocket.Bind(ActionEndPoint); }