elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ... 526
141  Programación / .NET (C#, VB.NET, ASP) / Re: [DUDA C#] Pasar array por sockets en: 2 Marzo 2013, 02:47 am
Bueno, tal vez no te resulte tan fácil la implementación :xD

Servidor
Código
  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;
  7. using System.Net.Sockets;
  8. using System.Runtime.Serialization.Formatters.Binary;
  9. using System.IO;
  10.  
  11. namespace TcpServer
  12. {
  13.    class Program
  14.    {
  15.        static void Main(string[] args)
  16.        {
  17.            //nos ponemos a la escucha
  18.            TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 31337);
  19.            tcpListener.Start();
  20.  
  21.            //buffer temporal para recibir data
  22.            byte[] buffer = new byte[256];
  23.            //el encargado de deserializar la data recibida
  24.            BinaryFormatter formatter = new BinaryFormatter();
  25.            //una lista auxiliar para ir almacenando los bytes
  26.            List<byte> byteList = new List<byte>();
  27.  
  28.            while (true)
  29.            {
  30.                Console.WriteLine("Esperando data :)");
  31.  
  32.                //acepto la conexión
  33.                TcpClient tcpClient = tcpListener.AcceptTcpClient();
  34.                NetworkStream networkStream = tcpClient.GetStream();
  35.  
  36.                //leo y almaceno en buffer
  37.                while (networkStream.Read(buffer, 0, buffer.Length) > 0)
  38.                {
  39.                    //dado que uso el mismo buffer siempre, voy almacenando los bytes en una lista
  40.                    byteList.AddRange(buffer.ToList());
  41.                }
  42.  
  43.                networkStream.Close();
  44.                tcpClient.Close();
  45.  
  46.                //stream auxiliar para luego deserializar
  47.                using (MemoryStream memoryStream = new MemoryStream(byteList.ToArray()))
  48.                {
  49.                    //se deserializa y castea a tipo correcto
  50.                    int[] data = (int[])formatter.Deserialize(memoryStream);
  51.  
  52.                    //simplemente para mostrar la data
  53.                    foreach (int i in data)
  54.                    {
  55.                        Console.WriteLine("Se recibió el número {0}", i);
  56.                    }
  57.                }
  58.            }
  59.        }
  60.    }
  61. }

Cliente
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Sockets;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace tcpClient
  11. {
  12.    class Program
  13.    {
  14.        static void Main(string[] args)
  15.        {
  16.            //la data que voy a enviar
  17.            int[] data = new int[] { 18, 10, 13, 89 };
  18.  
  19.            TcpClient tcpClient = new TcpClient("localhost", 31337);
  20.  
  21.            using (NetworkStream networkStream = tcpClient.GetStream())
  22.            {
  23.                using (MemoryStream memoryStream = new MemoryStream())
  24.                {
  25.                    BinaryFormatter formatter = new BinaryFormatter();
  26.                    //serializo la data en el stream auxiliar
  27.                    formatter.Serialize(memoryStream, data);
  28.                    byte[] buffer = memoryStream.GetBuffer();
  29.  
  30.                    //envio la data
  31.                    networkStream.Write(buffer, 0, buffer.Length);
  32.                }
  33.            }
  34.  
  35.            tcpClient.Close();
  36.        }
  37.    }
  38. }

Lo he comentado, así que espero se entienda ;)

Saludos
142  Programación / .NET (C#, VB.NET, ASP) / Re: [DUDA C#] Pasar array por sockets en: 1 Marzo 2013, 21:16 pm
Es muy fácil, más tarde te pego código ;) (bastante más tarde :xD)

Saludos
143  Programación / .NET (C#, VB.NET, ASP) / Re: [DUDA C#] Pasar array por sockets en: 28 Febrero 2013, 22:46 pm
Lo que haces es serializar el array de un lado, y deserializar del otro :P
BinaryFormatter y array de bytes :P
http://msdn.microsoft.com/es-uy/library/system.runtime.serialization.formatters.binary.binaryformatter(v=vs.80).aspx

Saludos
144  Programación / .NET (C#, VB.NET, ASP) / Re: CustomValidator en: 27 Febrero 2013, 18:21 pm
Cambiando de tema, ¿VB.NET por algo en particular? Tienes NetJava por nick, lo más lógico hubiese sido C# :P

Saludos
145  Programación / .NET (C#, VB.NET, ASP) / Re: CustomValidator en: 26 Febrero 2013, 17:36 pm
http://msdn.microsoft.com/es-es/library/f5db6z8k(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Saludos
146  Programación / Desarrollo Web / Re: duda en un form en: 26 Febrero 2013, 00:33 am
Lo mejor es agregar el texto o no en los eventos focus y blur, y no en el click, o ir directamente al nuevo atributo de HTML5, placeholder
Código
  1. <input type="text" placeholder="Ingrese valor" />

Saludos
147  Programación / Scripting / Re: Averiguar si un fichero esta abierto en: 25 Febrero 2013, 14:21 pm
Es verdad!

Acabo de probar con un archivo en notepad++ y no lo muestra :huh:
148  Programación / Scripting / Re: Averiguar si un fichero esta abierto en: 25 Febrero 2013, 14:13 pm
Acabo de probar de ese modo y funciona bien :-\

Saludos
149  Programación / Scripting / Re: Averiguar si un fichero esta abierto en: 25 Febrero 2013, 13:52 pm
No dices específicamente en que lenguaje necesitas hacerlo, así que supongo que es batch.
En la suite de Sysinternals tienes handle, con el cual puedes conseguir eso.

Saludos
150  Programación / PHP / Re: Debería aprenderse HTML, CSS javascript antes que PHP? en: 25 Febrero 2013, 13:19 pm
A mi criterio, si lo quieres aprender por separado, entonces si :)

Saludos
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [15] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ... 526
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines