DirectP1ClientCreator.cs 783 B

123456789101112131415161718192021222324252627282930313233
  1. using LJLib.Net.SPI.Client;
  2. using System;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using LJLib.IP;
  6. namespace LJLib.Client
  7. {
  8. public sealed class DirectP1ClientCreator : LJClientCreator
  9. {
  10. private string _url;
  11. private IPAddress _ip = null;
  12. private int _port;
  13. public DirectP1ClientCreator(String url, int port)
  14. {
  15. _url = url;
  16. _port = port;
  17. }
  18. public override ILJClient newClient()
  19. {
  20. if (_ip == null)
  21. {
  22. _ip = IPUtils.GetURLIPv4(_url);
  23. }
  24. var tcpClient = new TcpClient();
  25. tcpClient.Connect(_ip, _port);
  26. return new P1Client(tcpClient.GetStream());
  27. }
  28. }
  29. }