AsyncClientBase.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace NetCore31BACNetTransfor
  5. {
  6. public class AsyncClientBase
  7. {
  8. private List<string> sendList = new List<string>();
  9. private List<string> receiveList = new List<string>();
  10. private int packetSize = 1000;
  11. public AsyncClientBase(int packetSize)
  12. {
  13. this.packetSize = packetSize;
  14. }
  15. public virtual bool IsConnected()
  16. {
  17. return false;
  18. }
  19. public virtual void Start()
  20. {
  21. }
  22. public virtual void Stop()
  23. {
  24. }
  25. public void PushSend(string bag)
  26. {
  27. lock (this.sendList)
  28. {
  29. this.sendList.Add(bag);
  30. while (this.sendList.Count > this.packetSize)
  31. {
  32. this.sendList.RemoveAt(0);
  33. }
  34. }
  35. }
  36. public string PopSend()
  37. {
  38. string result = null;
  39. lock (this.sendList)
  40. {
  41. if (this.sendList.Count > 0)
  42. {
  43. result = this.sendList[0];
  44. this.sendList.RemoveAt(0);
  45. }
  46. }
  47. return result;
  48. }
  49. public void PushReceive(string bag)
  50. {
  51. lock (this.receiveList)
  52. {
  53. this.receiveList.Add(bag);
  54. while (this.receiveList.Count > this.packetSize)
  55. {
  56. this.receiveList.RemoveAt(0);
  57. }
  58. }
  59. }
  60. public string PopReceive()
  61. {
  62. string result = null;
  63. lock (this.receiveList)
  64. {
  65. if (this.receiveList.Count > 0)
  66. {
  67. result = this.receiveList[0];
  68. this.receiveList.RemoveAt(0);
  69. }
  70. }
  71. return result;
  72. }
  73. }
  74. }