Sockets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WAkthar

    Sockets

    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]

    #2
    Re: Sockets

    You have to use the TcpClient class of the System.Net.Sock ets 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:
    MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.


    "WAkthar" <wakthar@hotmai l.com> escribió en el mensaje
    news:%23cZhM4tV FHA.3488@tk2msf tngp13.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]


    Comment

    • WAkthar

      #3
      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 serverSockStrea m = new NetworkStream(s erverSocket);
      serverStreamWri ter = new StreamWriter(se rverSockStream) ;
      serverStreamRea der = new StreamReader(se rverSockStream) ;

      serverStreamWri ter.WriteLine(" Hi!");
      serverStreamWri ter.Flush();

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




      "Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAM sogecable.com> wrote in
      message news:OFYozIuVFH A.3140@TK2MSFTN GP14.phx.gbl...[color=blue]
      > You have to use the TcpClient class of the System.Net.Sock ets 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@hotmai l.com> escribió en el mensaje
      > news:%23cZhM4tV FHA.3488@tk2msf tngp13.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]


      Comment

      • stork

        #4
        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.

        Comment

        • Ignacio Machin \( .NET/ C# MVP \)

          #5
          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@hotmai l.com> wrote in message
          news:%23cZhM4tV FHA.3488@tk2msf tngp13.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]


          Comment

          Working...