C# Network... Need Suggestions.

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

    #1

    C# Network... Need Suggestions.

    I want to transfer n number of binary files from a server
    to a client one by one.

    I am using TcpListener and TcpClient.

    Any suggestions?

    mE
  • Peter Koen

    #2
    Re: C# Network... Need Suggestions.

    "mEEEEE" <anonymous@disc ussions.microso ft.com> wrote in news:05f701c39a d3
    $99206580$a6012 80a@phx.gbl:
    [color=blue]
    > I want to transfer n number of binary files from a server
    > to a client one by one.
    >
    > I am using TcpListener and TcpClient.
    >
    > Any suggestions?
    >
    > mE
    >[/color]

    TcpClient tc = tcpListener.Acc eptTcpClient();
    NetworkStream ns = tc.GetStream();

    IAsyncResult iar = ns.BeginWrite(b ytebuffer, offset, size, null, null);

    //do some other processing

    try
    {
    ns.EndWrite(IAs yncResult);
    }
    catch
    {
    //Networkerrors go here
    }


    other side:
    TcpClient tc = new TcpClient();

    tc.Connect(.... ...)

    Networkstream ns = tc.GetStream();

    IAsyncResult iar = ns.BeginRead(.. ....)


    //do some other processing

    try
    {
    ns.EndRead(IAsy ncResult);
    }
    catch
    {
    //Networkerrors go here
    }


    of course you could also use AsyncCallbacks so that you don't have
    explicitely to wait for the end of the send/receive methods.

    --
    best regards

    Peter Koen
    -----------------------------------
    MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS

    Comment

    Working...