fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Net.Sockets;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15.  
  16. namespace SendFile
  17. {
  18. public partial class Form1 : Form
  19. {
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. public TcpListener listener;
  26.  
  27. private void button1_Click(object sender, EventArgs e)
  28. {
  29. Thread trd = new Thread(new ThreadStart(this.Serwer));
  30. trd.Start();
  31.  
  32. }
  33.  
  34. public void Serwer()
  35. {
  36. listener = new TcpListener(IPAddress.Any, 1234);
  37. listener.Start();
  38.  
  39. TcpClient client = listener.AcceptTcpClient();
  40. NetworkStream stream = client.GetStream();
  41.  
  42. if (client.Connected)
  43. Debug.Write("podłączony");
  44.  
  45. readFile(stream, client);
  46. listener.Stop();
  47.  
  48. }
  49.  
  50. public void sendFile(NetworkStream s)
  51. {
  52. FileStream filestream = new FileStream(@"C:\Users\Piotr\Desktop\folderek\zdj.png", FileMode.Open);
  53. byte[] data = new byte[filestream.Length];
  54. filestream.Read(data, 0, (int)filestream.Length);
  55. s.Write(data, 0, (int)filestream.Length);
  56.  
  57. //File.WriteAllBytes(@"C:\Users\Piotr\Desktop\folderek\zdjecie.png", data);
  58. }
  59.  
  60. private void button2_Click(object sender, EventArgs e)
  61. {
  62. TcpClient client = new TcpClient();
  63. client.Connect(ip.Text, 1234);
  64.  
  65. NetworkStream stream = client.GetStream();
  66. sendFile(stream);
  67.  
  68. stream.Close();
  69. client.Close();
  70. }
  71.  
  72. public void send(string text, NetworkStream s)
  73. {
  74. byte[] bytes = Encoding.UTF8.GetBytes(text);
  75. s.Write(bytes, 0, bytes.Length);
  76. /*byte[] bytes = BitConverter.GetBytes(number);
  77.   s.Write(bytes, 0, bytes.Length); */
  78. }
  79.  
  80. public void read(NetworkStream s, TcpClient client)
  81. {
  82. byte[] readBytes = new byte[client.ReceiveBufferSize];
  83. s.Read(readBytes, 0, Convert.ToInt32(client.ReceiveBufferSize));
  84. string result = Encoding.UTF8.GetString(readBytes);
  85. MessageBox.Show(result.ToString());
  86. }
  87.  
  88. public void readFile(NetworkStream s, TcpClient client)
  89. {
  90. byte[] fileBytes = new byte[client.ReceiveBufferSize];
  91. s.Read(fileBytes, 0, Convert.ToInt32(client.ReceiveBufferSize));
  92. string path = @ścieżka.Text;
  93. File.WriteAllBytes(path, fileBytes);
  94.  
  95. MessageBox.Show("Zapisano plik w: " + path);
  96. }
  97.  
  98. private void Form1_Load(object sender, EventArgs e)
  99. {
  100. /*string text ="Jakis tekst";
  101.   byte[] bytes = Encoding.ASCII.GetBytes(text);
  102.   MessageBox.Show(bytes.Length.ToString());
  103.   byte[] bytes = BitConverter.GetBytes(101010);
  104.   MessageBox.Show(bytes.Length.ToString()); */
  105.  
  106. }
  107. }
  108. }
  109.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(13,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
prog.cs(14,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty