Xmas
14-11-2009, 21:21
ciao a tutti,
premetto che programmo da anni in c++ ma non conosco molto bene l'ambiente .net di ms.
Ho questo problema.
Due programmi, uno client scritto in vb.net ed uno server scritto in c++ sotto linux rh5 comunicano via tcp.
Il primo ha questa struttura definita:
<System.Serializable()> Structure MyTcpBlockData
Public id As UInt16
Public len As UInt16
Public type As UInt16
Public sendBytes As [Byte]()
End Structure
Il secondo ha quest'altra:
typedef struct S__MESSAGE_STATUS
{
unsigned short int id;
unsigned short int len;
unsigned short int type;
char * buffer;
} msg_status_t;
Ora come posso passare la struttura del programma vb al server linux via socket tcp???
Ho provato ad utilizzare la serialize di .net come mostrato nel codice seguente:
(Ovviamente l'oggetto tcpclient è già inizializzato e la connessione è già attiva)
Dim networkStream As NetworkStream = tcpclient.GetStream()
Dim bf As New Formatters.Binary.BinaryFormatter()
Dim oStream As New System.IO.MemoryStream()
Dim data As New MyTcpBlockData
data.id = 1
data.len = 6
data.type = 3
data.sendBytes = Encoding.ASCII.GetBytes("testo")
oStream.SetLength(Len(data))
bf.Serialize(oStream, data)
oStream.Position = 0
Dim buf(CInt(oStream.Length)) As Byte
Dim iRet As Int32 = oStream.Read(buf, 0, buf.Length)
oStream.Close()
networkStream.Write(buf, 0, buf.Length - 1)
Purtroppo lato server ricevo molti più bytes di quelli che mi sarei atteso (2 bytes per ciascun unsigned short int) quindi 6 bytes in totale più i cinque bytes della stringa, totale 11 bytes. Invece ricevo 178 bytes.
Ovviamente lato server non posso utilizzare la deserialize di .net, immagino che il problema sia questo.
Cmq, mi potete suggerire un metodo rapido e sicuro per fare questo tipo di operazioni???
grazie a chiunque vorra' fornirmi qualche aiuto....
;)
premetto che programmo da anni in c++ ma non conosco molto bene l'ambiente .net di ms.
Ho questo problema.
Due programmi, uno client scritto in vb.net ed uno server scritto in c++ sotto linux rh5 comunicano via tcp.
Il primo ha questa struttura definita:
<System.Serializable()> Structure MyTcpBlockData
Public id As UInt16
Public len As UInt16
Public type As UInt16
Public sendBytes As [Byte]()
End Structure
Il secondo ha quest'altra:
typedef struct S__MESSAGE_STATUS
{
unsigned short int id;
unsigned short int len;
unsigned short int type;
char * buffer;
} msg_status_t;
Ora come posso passare la struttura del programma vb al server linux via socket tcp???
Ho provato ad utilizzare la serialize di .net come mostrato nel codice seguente:
(Ovviamente l'oggetto tcpclient è già inizializzato e la connessione è già attiva)
Dim networkStream As NetworkStream = tcpclient.GetStream()
Dim bf As New Formatters.Binary.BinaryFormatter()
Dim oStream As New System.IO.MemoryStream()
Dim data As New MyTcpBlockData
data.id = 1
data.len = 6
data.type = 3
data.sendBytes = Encoding.ASCII.GetBytes("testo")
oStream.SetLength(Len(data))
bf.Serialize(oStream, data)
oStream.Position = 0
Dim buf(CInt(oStream.Length)) As Byte
Dim iRet As Int32 = oStream.Read(buf, 0, buf.Length)
oStream.Close()
networkStream.Write(buf, 0, buf.Length - 1)
Purtroppo lato server ricevo molti più bytes di quelli che mi sarei atteso (2 bytes per ciascun unsigned short int) quindi 6 bytes in totale più i cinque bytes della stringa, totale 11 bytes. Invece ricevo 178 bytes.
Ovviamente lato server non posso utilizzare la deserialize di .net, immagino che il problema sia questo.
Cmq, mi potete suggerire un metodo rapido e sicuro per fare questo tipo di operazioni???
grazie a chiunque vorra' fornirmi qualche aiuto....
;)