Send File By TcpClient generate SocketException<p>  <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>private void SendFile(string address)<br>        {<br>            TcpClient tClient = new TcpClient(new IPEndPoint(IPAddress.Loopback , TcpPort));</p> <p>                //  Generate SocketException</p> <p>                //  No connection could be made because the target machine actively refused it</p> <p>                tClient.Connect(IPAddress.Loopback , TcpPort);  // ErrorCode=10061</p> <p>                NetworkStream sendNetStm = tClient.GetStream();</p> <p>                FileStream sendFileStm = new FileStream(address, FileMode.Open);</p> <p>                byte[] buffer = new byte[256];<br>                  int count;</p> <p>                while ((count = sendFileStm.Read(buffer, 0, buffer.Length)) != 0)<br>                {<br>                    sendNetStm.Write(buffer, 0, count);<br>                }</p> <p>                sendFileStm.Close();<br>                   tClient.Close();<br>         }</p></div></div> <p> </p> <p>Why?How to solve?</p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z15aea284-7295-41ad-be98-f17be4a12e33http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#15aea284-7295-41ad-be98-f17be4a12e33http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#15aea284-7295-41ad-be98-f17be4a12e33youTehttp://social.msdn.microsoft.com/Profile/en-US/?user=youTeSend File By TcpClient generate SocketException<p>  <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>private void SendFile(string address)<br>        {<br>            TcpClient tClient = new TcpClient(new IPEndPoint(IPAddress.Loopback , TcpPort));</p> <p>                //  Generate SocketException</p> <p>                //  No connection could be made because the target machine actively refused it</p> <p>                tClient.Connect(IPAddress.Loopback , TcpPort);  // ErrorCode=10061</p> <p>                NetworkStream sendNetStm = tClient.GetStream();</p> <p>                FileStream sendFileStm = new FileStream(address, FileMode.Open);</p> <p>                byte[] buffer = new byte[256];<br>                  int count;</p> <p>                while ((count = sendFileStm.Read(buffer, 0, buffer.Length)) != 0)<br>                {<br>                    sendNetStm.Write(buffer, 0, count);<br>                }</p> <p>                sendFileStm.Close();<br>                   tClient.Close();<br>         }</p></div></div> <p> </p> <p>Why?How to solve?</p>Sun, 10 Jun 2007 12:24:09 Z2007-06-10T12:24:09Zhttp://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#729e28b2-e015-44e0-86f7-430b76bc2bcahttp://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#729e28b2-e015-44e0-86f7-430b76bc2bcaAlan J. McFarlanehttp://social.msdn.microsoft.com/Profile/en-US/?user=Alan%20J.%20McFarlaneSend File By TcpClient generate SocketException<p>What's the exception?!  We're not psychic... :-,)  Where does it occur (what's its stack trace)?</p> <p> </p> <p>However, you should probably change the first line to be <strong>TcpClient tClient = new TcpClient();</strong></p> <p>I presume you have another application listening on port <strong>TcpPort</strong>, maybe a TcpListener of your own in another program...?</p>Mon, 11 Jun 2007 10:05:46 Z2007-06-11T10:05:46Zhttp://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#85f852d8-0ef0-4ad8-b3dd-14c0f6175ea4http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#85f852d8-0ef0-4ad8-b3dd-14c0f6175ea4youTehttp://social.msdn.microsoft.com/Profile/en-US/?user=youTeSend File By TcpClient generate SocketExceptionThanks for your reply,I'v been edit the thread,please help me,and I can't speak English,but I'm learning.Mon, 11 Jun 2007 11:09:56 Z2007-06-11T11:09:56Zhttp://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#7b853a44-b9c1-4f77-89b7-32364d4306d2http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/15aea284-7295-41ad-be98-f17be4a12e33#7b853a44-b9c1-4f77-89b7-32364d4306d2Alan J. McFarlanehttp://social.msdn.microsoft.com/Profile/en-US/?user=Alan%20J.%20McFarlaneSend File By TcpClient generate SocketException<p><font size=2>Err...  Did you change</font></p> <p><font size=2>   TcpClient tClient = new TcpClient(new IPEndPoint(IPAddress.Loopback , TcpPort));</font></p> <p><font size=2>to</font></p> <p><font size=2>    <strong>TcpClient tClient = new TcpClient();</strong></font></p> <p><font size=2></font> </p> <p><font size=2>Do you still get an exception?  Which exception?  SocketException, ArgumentException?  What line?</font></p>Tue, 12 Jun 2007 14:18:01 Z2007-06-12T14:18:01Z