Connecting Tech Pros Worldwide Forums | Help | Site Map

Sockets

WAkthar
Guest
 
Posts: n/a
#1: Nov 17 '05
I am in the process of converting an MFC client and server application to
C#.

The communication between the client and server was done using simple
WM_COPYDATA. I want to use sockets for the C# version.



Can someone show me how to send and receive data structures using sockets?

A simple client and server example would be much appreciated.



Thanks in advance.




Carlos J. Quintero [.NET MVP]
Guest
 
Posts: n/a
#2: Nov 17 '05

re: Sockets


You have to use the TcpClient class of the System.Net.Sockets namespace.

Search in Google "TcpClient .NET" to get samples.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"WAkthar" <wakthar@hotmail.com> escribió en el mensaje
news:%23cZhM4tVFHA.3488@tk2msftngp13.phx.gbl...[color=blue]
>I am in the process of converting an MFC client and server application to
>C#.
>
> The communication between the client and server was done using simple
> WM_COPYDATA. I want to use sockets for the C# version.
>
>
>
> Can someone show me how to send and receive data structures using sockets?
>
> A simple client and server example would be much appreciated.
>
>
>
> Thanks in advance.
>
>
>[/color]


WAkthar
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Sockets


Cheers..but I have searched most places without finding anything to do with
sending strcutures through sockets.

Most examples use for example

NetworkStream serverSockStream = new NetworkStream(serverSocket);
serverStreamWriter = new StreamWriter(serverSockStream);
serverStreamReader = new StreamReader(serverSockStream);

serverStreamWriter.WriteLine("Hi!");
serverStreamWriter.Flush();

This is ok for sending string messages but what about sending and receiving
data structures???




"Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAMsogecable.com> wrote in
message news:OFYozIuVFHA.3140@TK2MSFTNGP14.phx.gbl...[color=blue]
> You have to use the TcpClient class of the System.Net.Sockets namespace.
>
> Search in Google "TcpClient .NET" to get samples.
>
> --
>
> Best regards,
>
> Carlos J. Quintero
>
> MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
> You can code, design and document much faster.
> Free resources for add-in developers:
> http://www.mztools.com
>
> "WAkthar" <wakthar@hotmail.com> escribió en el mensaje
> news:%23cZhM4tVFHA.3488@tk2msftngp13.phx.gbl...[color=green]
>>I am in the process of converting an MFC client and server application to
>>C#.
>>
>> The communication between the client and server was done using simple
>> WM_COPYDATA. I want to use sockets for the C# version.
>>
>>
>>
>> Can someone show me how to send and receive data structures using
>> sockets?
>>
>> A simple client and server example would be much appreciated.
>>
>>
>>
>> Thanks in advance.
>>
>>
>>[/color]
>
>[/color]


stork
Guest
 
Posts: n/a
#4: Nov 17 '05

re: Sockets


Buy the Ingo Rammer book about .NET remoting and read it before you
start to code anything.

You don't want to do straight up sockets. You really want to use .NET
remoting. It does all the work for you.

Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#5: Nov 17 '05

re: Sockets


Hi,

Well all you have to do is convert the struct in a byte[] , then send it as
usual, in the receiving end you must provide a method to convert a byte[]
back to the struct.

You could use the BitConverter class for this. insert two method in your
struct like this:

struct X
{
public byte[] GetBytes() { ... {

public static X FromBytes( byte[] bytes ) { }

}


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"WAkthar" <wakthar@hotmail.com> wrote in message
news:%23cZhM4tVFHA.3488@tk2msftngp13.phx.gbl...[color=blue]
>I am in the process of converting an MFC client and server application to
>C#.
>
> The communication between the client and server was done using simple
> WM_COPYDATA. I want to use sockets for the C# version.
>
>
>
> Can someone show me how to send and receive data structures using sockets?
>
> A simple client and server example would be much appreciated.
>
>
>
> Thanks in advance.
>
>
>[/color]


Closed Thread