public void Run() { try { fs = new FileStream(fichName, FileMode.Open, FileAccess.Read); client = new UdpClient(); bFile = Encoding.UTF8.GetBytes(fichName); Packet newFile = new NewFile((int)PacketBodyType.NewFile, bFile.Length, bFile); bSent = encoding.Encode(newFile); client.Send(bSent, bSent.Length, SERVER, SERVERPORT); ChangeState(new WaitConfirmation(this)); while (!finish) { _state.HandleMessage(); } Console.WriteLine("Transferencia del archivo finalizada"); } catch (Exception e) { Console.WriteLine("Exception: {0}", e.Message); } finally { client.Close(); } Console.ReadKey(); }
public void SendConfirmation(int packetType, int nSec) { byte[] body = Encoding.UTF8.GetBytes("OK"); int bodyLength = body.Length; Packet Ack = new Packet(nSec, packetType, bodyLength, body); bSent = encoding.Encode(Ack); client.Send(bSent, bSent.Length, remoteIPEndPoint); }