fork(1) 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 int size;
  35.  
  36. public void Serwer()
  37. {
  38. listener = new TcpListener(IPAddress.Any, 1234);
  39. listener.Start();
  40.  
  41. TcpClient client = listener.AcceptTcpClient();
  42. NetworkStream stream = client.GetStream();
  43.  
  44. if (client.Connected)
  45. Debug.Write("podłączony");
  46.  
  47. size = read(stream, client);
  48. readFile(stream, client);
  49.  
  50. listener.Stop();
  51.  
  52. }
  53.  
  54. public void sendFile(NetworkStream s)
  55. {
  56. FileStream filestream = new FileStream(@"C:\Users\Piotr\Music\obok mnie.mp3", FileMode.Open);
  57. byte[] data = new byte[filestream.Length];
  58. filestream.Read(data, 0, (int)filestream.Length);
  59. progressBar1.Maximum = data.Length;;
  60.  
  61. send(data.Length, s);
  62.  
  63. Debug.WriteLine("Max: " + progressBar1.Maximum + ", Data: " + data.Length);
  64. for (int i = 0; i < data.Length; i++)
  65. {
  66. s.WriteByte(data[i]);
  67. progressBar1.Value = i;
  68. }
  69. }
  70.  
  71. private void button2_Click(object sender, EventArgs e)
  72. {
  73. TcpClient client = new TcpClient();
  74. client.Connect(ip.Text, 1234);
  75.  
  76. NetworkStream stream = client.GetStream();
  77.  
  78. sendFile(stream);
  79. //send(543678291, stream);
  80.  
  81. stream.Close();
  82. client.Close();
  83. }
  84.  
  85. public void send(int number, NetworkStream s)
  86. {
  87. /*byte[] bytes = Encoding.UTF8.GetBytes(text);
  88.   s.Write(bytes, 0, bytes.Length); */
  89. byte[] bytes = BitConverter.GetBytes(number);
  90. s.Write(bytes, 0, bytes.Length);
  91. }
  92.  
  93. public int read(NetworkStream s, TcpClient client)
  94. {
  95. byte[] readBytes = new byte[client.ReceiveBufferSize];
  96. s.Read(readBytes, 0, Convert.ToInt32(client.ReceiveBufferSize));
  97. //string result = Encoding.UTF8.GetString(readBytes);
  98. int result = BitConverter.ToInt32(readBytes, 0);
  99. MessageBox.Show(result.ToString());
  100. return result;
  101. }
  102.  
  103. public void readFile(NetworkStream s, TcpClient client)
  104. {
  105. byte[] fileBytes = new byte[size];
  106. Debug.WriteLine("Otrzymane: " + fileBytes.Length);
  107. int a = 0;
  108. while (a < size)
  109. {
  110. fileBytes[a] = (byte)s.ReadByte();
  111. a++;
  112.  
  113. }
  114.  
  115. string path = @ścieżka.Text;
  116. File.WriteAllBytes(path, fileBytes);
  117.  
  118. MessageBox.Show("Zapisano plik w: " + path);
  119. }
  120.  
  121. private void Form1_Load(object sender, EventArgs e)
  122. {
  123. /*string text ="Jakis tekst";
  124.   byte[] bytes = Encoding.ASCII.GetBytes(text);
  125.   MessageBox.Show(bytes.Length.ToString());
  126.   byte[] bytes = BitConverter.GetBytes(101010);
  127.   MessageBox.Show(bytes.Length.ToString()); */
  128. }
  129. }
  130. }
  131.  
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