Guest User

Untitled

a guest
Oct 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Sockets;
  7. using System.IO;
  8.  
  9. namespace Alexandria
  10. {
  11. class Client
  12. {
  13. TcpClient tcpClient = new TcpClient(AlexandriaMain.currentServer, 8080);
  14.  
  15. File file = new File("test.png", "");
  16.  
  17. public void fileGet(string fileName)
  18. {
  19. NetworkStream ns = tcpClient.GetStream();
  20. StreamWriter sw = new StreamWriter(ns);
  21.  
  22. sw.Write("GET:" + fileName);
  23. sw.Flush();
  24.  
  25. byte[] lengthBytes = new byte[16];
  26.  
  27. int read = ns.Read(lengthBytes, 0, 15);
  28. int length = BitConverter.ToInt32(lengthBytes, 0);
  29. byte[] buf = new byte[length];
  30. ns.Read(buf, 0, buf.Length);
  31.  
  32. file.Write(buf);
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment