Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.IO;
- namespace ConsoleApplication4
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- TcpClient klient = new TcpClient();
- klient.Connect("192.168.0.13", 20);
- NetworkStream stream = klient.GetStream();
- byte[] outer;
- byte[] inner= new byte[1024];
- string nazwa = null;
- string tekst=null;
- Console.WriteLine("nazwa pliku:");
- outer = Encoding.ASCII.GetBytes(Console.ReadLine());
- nazwa= Encoding.ASCII.GetString(outer);
- stream.Write(outer, 0, outer.Length);
- //Odpowiedź serwera
- stream.Read(inner, 0, inner.Length);
- tekst=System.Text.Encoding.ASCII.GetString(inner,0,inner.Length);
- StreamWriter pisz = File.CreateText(nazwa);
- pisz.Write(tekst);
- pisz.Close();
- Console.WriteLine("Zapisano plik: {0}", nazwa);
- klient.Close();
- stream.Close();
- }
- catch (SocketException e)
- {
- Console.WriteLine("Błąd przy połaczeniu z serwerem! Kod: " + e.Message);
- }
- catch (IOException e)
- {
- Console.WriteLine("Błąd. Możliwe, że serwer został rozłączony. Kod: " + e.Message);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement