My initial guess without the info requested by Alex is that the exception 
thrown has something to do with not being able to serialize your dataStruct 
instance. In that case the likely cause of the problem is that the dataStruct 
class is not decorated with the [Serializable] attribute.

-SteveL


On Apr 5, 2011, at 12:28 PM, Alex <[email protected]> wrote:

> Hi,
> 
> You could help us help you by telling us what exception you're
> getting. A self-contained test case also helps (the more you can
> reduce the amount of code, the better).
> 
> Regards,
> Alex
> 
> 2011/4/4 Leonel Florin Selles <[email protected]>:
>> I have created two applications that connect on the same machine and sent
>> an object, I used Socket to connect, but when the client sends data to the
>> server, and the server revived the data and try to  Deserialize is when it
>>  get me out with one exception.
>> 
>> here is the client and server, the object that they use to communicate and
>>  the class to serialize and deserialize
>> 
>> dataStruct
>> -----------------------------------------
>> using System;
>> 
>> namespace server
>> {
>>        public class dataStruct
>>        {
>>                public dataStruct ()
>>                {
>>                }
>> 
>>                public String clientName;
>>                public Int32 clientPid;
>>                public String host;
>>                public String bd;
>>                public String user;
>>                public String pass;
>>                public String usersCheck;
>>                public Boolean systemTryIcon;
>>                public String adminpass;
>> 
>>                public enum signals
>>                {
>>                        ConfFileExist,
>>                        ConfFileEmpty,
>>                        SocketServerNoStart,
>>                        ClientMalCerrado,
>>                        ClientBienCerrado,
>>                        TmServiceExist,
>>                        TmServiseNoExist,
>>                        CerrarSesion,
>>                        SendMeConfData,
>>                        SaveThisConfData,
>>                        ApagerEquipo,
>>                        ReiniciarEquipo,
>>                        ObjetoBdNoInicia,
>>                        BindToSocketBrouk,
>>                        ConectarBdImposible,
>>                        SocketNoListen,
>>                        ConsultaFallo,
>>                        ConsultaOK,
>>                        ExtractConsultaFallo,
>>                        ExtractConsultaOk,
>>                        PCNoExiste
>>                }
>> 
>>                public signals orden;
>> 
>>        }
>> }
>> 
>> ------------------------------------------------------
>> 
>> Serialice
>> -----------------------------------------------------
>> using System;
>> using System.Runtime.Serialization.Formatters.Binary;
>> using System.IO;
>> 
>> namespace server
>> {
>>        public class serializacion
>>        {
>>                public serializacion ()
>>                {
>>                }
>>                public static byte[] Serialize (Object objeto)
>>                {
>>                        BinaryFormatter formater = new BinaryFormatter ();
>>                        MemoryStream mem = new MemoryStream ();
>>                        formater.Serialize (mem, objeto);
>>                        return mem.GetBuffer ();
>>                }
>>                public static System.Object DeSerialize (byte[] listaByte)
>>                {
>>                        BinaryFormatter formater = new BinaryFormatter ();
>>                        MemoryStream mem = new MemoryStream ();
>> 
>>                        mem.Write (listaByte, 0, listaByte.Length);
>>                        mem.Seek (0, 0);
>>                        return formater.Deserialize (mem);
>>                }
>>        }
>> }
>> ----------------------------------------------------------------
>> 
>> 
>> client
>> ------------------------------------
>> using System;
>> using System.Text;
>> using System.IO;
>> using System.Net.Sockets;
>> 
>> namespace cliente
>> {
>>        class MainClass
>>        {
>>                public static void Main (string[] args)
>>                {
>>                        byte[] sendData;
>>                        byte[] recvData;
>> 
>>                        Socket clientSocket = new Socket 
>> (AddressFamily.InterNetwork,
>> SocketType.Stream, ProtocolType.IP);
>>                        clientSocket.Connect ("localhost", 4069);
>> 
>>                        dataStruct structura = new dataStruct ();
>> 
>>                        structura.clientName = "Pepe";
>>                        structura.clientPid = 1234;
>>                        structura.host = "localhost";
>>                        structura.bd = "Tmaquina";
>>                        structura.user = "TmaquinaLoco";
>>                        structura.pass = "EstoNoCuadra";
>>                        structura.usersCheck = "estudiante,florin";
>>                        structura.systemTryIcon = true;
>>                        structura.adminpass = "pepeloco";
>>                        structura.orden = dataStruct.signals.ApagerEquipo;
>> 
>>                        sendData = serializacion.Serialize (structura);
>> 
>>                        clientSocket.Send (sendData, 0, sendData.Length, 
>> SocketFlags.None);
>> 
>> 
>>                }
>>        }
>> }
>> --------------------------------------------------
>> 
>> 
>> 
>> Server
>> ---------------------------------------------
>> using System;
>> using System.Runtime.InteropServices;
>> using System.Net;
>> using System.Net.Sockets;
>> using System.Collections;
>> using System.Text;
>> 
>> namespace server
>> {
>>        class MainClass
>>        {
>>                public static void Main (string[] args)
>>                {
>>                        byte[] sendData;
>>                        byte[] rcvData;
>>                        int puerto = 4069;
>> 
>>                        Socket socketServer = new Socket 
>> (AddressFamily.InterNetwork,
>> SocketType.Stream, ProtocolType.IP);
>>                        Socket socketClient;
>> 
>>                        socketServer.Bind (new IPEndPoint (IPAddress.Any, 
>> puerto));
>>                        socketServer.Listen (100);
>> 
>>                        socketClient = socketServer.Accept ();
>>                        rcvData = new byte[4000];
>>                        socketClient.Receive (rcvData, 0, rcvData.Length, 
>> SocketFlags.None);
>> 
>>                        dataStruct datos = new dataStruct ();
>> 
>>                        datos = (dataStruct)serializacion.DeSerialize 
>> (rcvData);
>> 
>>                        Console.Read ();
>> 
>>                }
>>        }
>> }
>> ----------------------------------------------------------------
>> 
>> helpppppppppppppppppppp
>> 
>> _______________________________________________
>> Mono-list maillist  -  [email protected]
>> http://lists.ximian.com/mailman/listinfo/mono-list
>> 
> _______________________________________________
> Mono-list maillist  -  [email protected]
> http://lists.ximian.com/mailman/listinfo/mono-list
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to