Click here to Skip to main content
15,910,234 members
Home / Discussions / C#
   

C#

 
General.NET to pdf Pin
krishnan10-Jul-02 9:01
krishnan10-Jul-02 9:01 
GeneralRe: .NET to pdf Pin
Chris Rickard10-Jul-02 12:43
Chris Rickard10-Jul-02 12:43 
GeneralRe: .NET to pdf Pin
krishnan11-Jul-02 3:17
krishnan11-Jul-02 3:17 
GeneralRe: .NET to pdf Pin
Andrew Connell11-Jul-02 3:19
Andrew Connell11-Jul-02 3:19 
GeneralRe: .NET to pdf Pin
krishnan11-Jul-02 6:31
krishnan11-Jul-02 6:31 
GeneralRe: .NET to pdf Pin
Andrew Connell11-Jul-02 8:56
Andrew Connell11-Jul-02 8:56 
GeneralRe: .NET to pdf Pin
krishnan11-Jul-02 8:58
krishnan11-Jul-02 8:58 
GeneralSerialization over socket Pin
iGN10-Jul-02 6:05
iGN10-Jul-02 6:05 
I'm trying to serialize a number of simple classes over socket, and it seems to work pretty good locally. I connect to the server, which sends me a simple text, which client prints, then I go into a loop on both sides where client initiates requests by creating objects of type "Request" (which I have defined) and serializing them over the socket.

The server then deserializes them, and creates an object of type "Response", which it then serializes back.

It all work very well, until I try connecting _from another machine_.

I get a connection, but the data just isn't sent (from server to client. I manage to send data from the client to the server).

I've tries serializing to memory and then sending the socket, but it seems to be incompatible (somehow) with just using a plain binaryformatter onto the networkstream.

Here's the server code:

private void SendResponse(Response p_response)
{
try
{
BinaryFormatter t_binaryFormatter = new BinaryFormatter();
NetworkStream t_networkStream = new NetworkStream(m_socket);
t_binaryFormatter.Serialize(t_networkStream, p_response);
}
catch (System.Exception e)
{
m_app.log(e, this);
}
}

(Works well locally, but not from another machine, both doing TCP/IP).

Alternative server-code:

private void SendResponse(Response p_response)
{
try
{
BinaryFormatter t_binaryFormatter = new BinaryFormatter();
MemoryStream t_memoryStream = new MemoryStream();
t_binaryFormatter.Serialize(t_memoryStream, p_response);
m_socket.Send(t_memoryStream.GetBuffer());
}
catch (System.Exception e)
{
m_app.log(e, this);
}
}

Works well even remotely for the first request, but after that I get this exception (in the client):

Exception: Binary stream does not contain a valid BinaryHeader, 0 possible causes, invalid stream or object version change between serialization and deserialization.

It seems there is superfluous data sent from the server when using the MemoryStream.

Any pointers? Thanks in advance.

Ideally, I would want to get it to work without using the MemoryStream.
GeneralPlease...Help...Question about checking/unchecking boxes Pin
cAptHiDDeN10-Jul-02 5:28
cAptHiDDeN10-Jul-02 5:28 
GeneralDatabase Problem Pin
BHBAD10-Jul-02 4:26
sussBHBAD10-Jul-02 4:26 
GeneralRe: Database Problem Pin
Mazdak10-Jul-02 9:14
Mazdak10-Jul-02 9:14 
GeneralRe: Database Problem Pin
Steve Severance10-Jul-02 10:49
Steve Severance10-Jul-02 10:49 
GeneralDragDrop inTree View Pin
Member 1697710-Jul-02 2:22
Member 1697710-Jul-02 2:22 
GeneralRe: DragDrop inTree View Pin
Bill Dean4-Sep-02 11:30
Bill Dean4-Sep-02 11:30 
QuestionAn unhandled exception? Pin
hunglin9-Jul-02 20:38
hunglin9-Jul-02 20:38 
AnswerRe: An unhandled exception? Pin
Andres Manggini10-Jul-02 10:14
Andres Manggini10-Jul-02 10:14 
GeneralAccessing position of desktop icons... Pin
gekoscan9-Jul-02 8:19
gekoscan9-Jul-02 8:19 
GeneralAmazon UK and Inside C# Pin
Michael P Butler9-Jul-02 8:17
Michael P Butler9-Jul-02 8:17 
GeneralRe: Amazon UK and Inside C# Pin
merlin987610-Jul-02 16:57
merlin987610-Jul-02 16:57 
GeneralRe: Amazon UK and Inside C# Pin
Christian Graus10-Jul-02 18:28
protectorChristian Graus10-Jul-02 18:28 
GeneralThe "good books" question... Pin
merlin98769-Jul-02 7:54
merlin98769-Jul-02 7:54 
GeneralRe: The "good books" question... Pin
Michael P Butler9-Jul-02 8:13
Michael P Butler9-Jul-02 8:13 
GeneralRe: The "good books" question... Pin
Eric Gunnerson (msft)10-Jul-02 7:42
Eric Gunnerson (msft)10-Jul-02 7:42 
GeneralRe: The "good books" question... Pin
merlin987610-Jul-02 16:54
merlin987610-Jul-02 16:54 
GeneralRe: The "good books" question... Pin
James T. Johnson10-Jul-02 21:03
James T. Johnson10-Jul-02 21:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.