Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Novlucker

#141
Bueno, tal vez no te resulte tan fácil la implementación :xD

Servidor
Código (csharp) [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace TcpServer
{
    class Program
    {
        static void Main(string[] args)
        {
            //nos ponemos a la escucha
            TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 31337);
            tcpListener.Start();

            //buffer temporal para recibir data
            byte[] buffer = new byte[256];
            //el encargado de deserializar la data recibida
            BinaryFormatter formatter = new BinaryFormatter();
            //una lista auxiliar para ir almacenando los bytes
            List<byte> byteList = new List<byte>();

            while (true)
            {
                Console.WriteLine("Esperando data :)");

                //acepto la conexión
                TcpClient tcpClient = tcpListener.AcceptTcpClient();
                NetworkStream networkStream = tcpClient.GetStream();

                //leo y almaceno en buffer
                while (networkStream.Read(buffer, 0, buffer.Length) > 0)
                {
                    //dado que uso el mismo buffer siempre, voy almacenando los bytes en una lista
                    byteList.AddRange(buffer.ToList());
                }

                networkStream.Close();
                tcpClient.Close();

                //stream auxiliar para luego deserializar
                using (MemoryStream memoryStream = new MemoryStream(byteList.ToArray()))
                {
                    //se deserializa y castea a tipo correcto
                    int[] data = (int[])formatter.Deserialize(memoryStream);

                    //simplemente para mostrar la data
                    foreach (int i in data)
                    {
                        Console.WriteLine("Se recibió el número {0}", i);
                    }
                }
            }
        }
    }
}


Cliente
Código (csharp) [Seleccionar]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace tcpClient
{
    class Program
    {
        static void Main(string[] args)
        {
            //la data que voy a enviar
            int[] data = new int[] { 18, 10, 13, 89 };

            TcpClient tcpClient = new TcpClient("localhost", 31337);

            using (NetworkStream networkStream = tcpClient.GetStream())
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    //serializo la data en el stream auxiliar
                    formatter.Serialize(memoryStream, data);
                    byte[] buffer = memoryStream.GetBuffer();

                    //envio la data
                    networkStream.Write(buffer, 0, buffer.Length);
                }
            }

            tcpClient.Close();
        }
    }
}


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

Saludos
#142
Es muy fácil, más tarde te pego código ;) (bastante más tarde :xD)

Saludos
#143
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
.NET (C#, VB.NET, ASP) / Re: CustomValidator
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
#146
Desarrollo Web / Re: duda en un form
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 (html4strict) [Seleccionar]
<input type="text" placeholder="Ingrese valor" />

Saludos
#147
Es verdad!

Acabo de probar con un archivo en notepad++ y no lo muestra :huh:
#148
Acabo de probar de ese modo y funciona bien :-\

Saludos
#149
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
A mi criterio, si lo quieres aprender por separado, entonces si :)

Saludos