Network Class Library (System.Net) ForumDiscuss using the System.Net namespace and associated Uri class in the .NET Framework to write code that leverages managed sockets, HTTP web requests, FTP, SMTP, P2P, etc.© 2009 Microsoft Corporation. All rights reserved.Sat, 28 Nov 2009 02:03:30 Zc6db59dc-d8a0-4b10-b925-253b94b87b55http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e61deee0-8388-4a2f-a122-cafea7c49473http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e61deee0-8388-4a2f-a122-cafea7c49473motevallizadehhttp://social.msdn.microsoft.com/Profile/en-US/?user=motevallizadehhow can i change window size(in packet)hi all<br/> how can i change window size(in packet) in a socket with connection oriented type?<br/> is that option available that can i change it?<hr class="sig">Thanks MotevallizadehFri, 27 Nov 2009 14:34:27 Z2009-11-28T02:03:30Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/6a22a294-e472-4904-91e6-f5b16f8114f8http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/6a22a294-e472-4904-91e6-f5b16f8114f8marcostewahttp://social.msdn.microsoft.com/Profile/en-US/?user=marcostewaTracing UDP broadcast packetsGood morning,<br/>I have a problem running a piece of code under Windows 7.<br/><br/>I have an hardware device plugged in my LAN. This device sends broadcast UDP packets, containing some information about it (its name, its ip address and so on).<br/>I wrote a simple test application (using .Net fx 3.5 and WPF) that sets up a socket and start listen for these packets in asynchronous mode.<br/>This piece of code works well under Windows XP SP2 (or SP3), but when I try to run it under Windows 7 I see nothing. I checked the firewall rules, and I removed all restrictions to my application, but the problem still remains.<br/><br/>The test application code is very simple: this is what I do on class constructor (30002 is the port number we decided the device must use to communicate inside our LAN, and 84 is the length of the packet sent by the device)<br/><br/> <pre lang="x-c#">EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002); this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); this._socket.Bind(endPoint); this._udpBuffer = new Byte[84];</pre> this is what I do in response of a Button click on my application (to start listen to packets)<br/><br/> <pre lang="x-c#">EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002); this._socket.BeginReceiveFrom(this._udpBuffer, 0, 84, SocketFlags.None, ref endPoint, new AsyncCallback(this.PacketReceived), null);</pre> and this is the code of PacketReceived callback<br/><br/> <pre lang="x-c#">EndPoint endPoint = new IPEndPoint(IPAddress.Any, 30002); this._socket.EndReceiveFrom(result, ref endPoint); // do something to track packets... // restart listening this._socket.BeginReceiveFrom(this._udpBuffer, 0, 84, SocketFlags.None, ref endPoint, new AsyncCallback(this.PacketReceived), null);</pre> As I said before, if I run this simple application under XP, everything goes well, and I see my packets as they arrive. On the contrary, when I run it under Windows 7 64bits, I see no packets. I did no test under Windows 7 32 bits (as we don't have any machine running it).<br/>To be more complete, I'm quite sure it's not a problem of the device, since if I use a sniffer program to trace network activity under Windows 7, I see all my UDP broadcast packets.<br/><br/>Thanks in advance for the help, and sorry for my English.<br/><br/>Marco Stevanato<br/>Aprilia Racing S.r.l.Thu, 26 Nov 2009 08:42:48 Z2009-11-27T12:47:54Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/22d29938-c8db-4a79-8510-95428a3329b7http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/22d29938-c8db-4a79-8510-95428a3329b7Sascha4321http://social.msdn.microsoft.com/Profile/en-US/?user=Sascha4321FtpWebRequest.BeginGetResponse hangs after 2 Requests to the same AddressHello.<br/><br/>I posted this problem in Visual C# General Forum (<a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/07f43d15-f680-4869-9af3-14cdc2ac1477">http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/07f43d15-f680-4869-9af3-14cdc2ac1477</a>) but they don't find a solution. The MSFT suggest me to post my problem here.<br/><br/>I need to ask many Ftp-Servers very frequently for new files. I have written a program, that does this with FtpWebRequest and asynchronous calls. Everything works fine, if the ftp-server exists. But if the address does not exist, the callback is called 2 times and then never again for this address. I wrote a small sample, to reproduce the behaviour.<br/><br/> <pre lang="x-c#">using System; using System.Net; using System.Threading; namespace FtpTest { class Program { private static ManualResetEvent resetEvent; static void Main(string[] args) { Console.WriteLine(&quot;Press RETURN to start...&quot;); Console.ReadLine(); resetEvent = new ManualResetEvent(false); WebRequest.DefaultWebProxy = null; for(int i = 0; i &lt; 5; i++) { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(&quot;ftp://1.2.3.4/abc&quot;); //request.ConnectionGroupName = Guid.NewGuid().ToString(); request.Credentials = new NetworkCredential(&quot;abc&quot;, &quot;def&quot;); request.UsePassive = false;Ad IAsyncResult asyncResult = request.BeginGetResponse(responseCallback, request); Console.WriteLine(&quot;Request &quot; + i + &quot; sent&quot;); resetEvent.WaitOne(30000); if (!asyncResult.IsCompleted) { request.Abort(); Console.WriteLine(&quot;Request &quot; + i + &quot; aborted&quot;); } resetEvent.Reset(); } } private static void responseCallback(IAsyncResult ar) { WebRequest request = (WebRequest)ar.AsyncState; WebResponse response = null; try { response = request.EndGetResponse(ar); Console.WriteLine(&quot;Response OK&quot;); } catch(Exception ex) { Console.WriteLine(&quot;ResponseError: &quot; + ex.Message); } finally { if(response != null) response.Close(); resetEvent.Set(); } } } }</pre> <br/>When I uncomment the line with ConnectionGroupName it works but with negative side-effects to the existing servers.<br/>When I use http instead of ftp everything works fine, too.<br/>Why does the FtpWebRequest &quot;forget&quot; to call the callback after 2 unsuccessful connectiontries?<br/><br/>I use Visual Studio 2008 (SP1), Target Framework 3.5 (SP1) on Windows Vista.<br/>The program shows this behaviour on a Windows Server 2008 and Server 2003, too. In both configurations Debug and Release.<br/>All security patches over Windows Update should be installed.<br/><br/>After further investigation with debugging into FtpWebRequest sourcecode I found out that FtpWebRequest holds a connection pool. If the pool is full, the class returns no new connections (but if I correctly understand the connection pool it registers a callback to wait for a free connection). With tracing on, you can see, that there are not created any sockets after the second (or somtimes the third) try. Without opening a socket, I cannot receive any callback. It seems, that the old connections are not pushed from the connection pool (I have waited for free connections about two hours).<br/>Unfortunately I found nothing to free the old connections manually. I will try to put a new ConnectionGroupName every time when the code reaches the request.Abort() method but I don't know if the old connections stay in memory until the program shuts down. My productive program is a service that must run 24/7.<br/><br/>I attached the trace of the sample.<br/><br/>System.Net Verbose: 0 : [0620] WebRequest::Create(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Information: 0 : [0620] FtpWebRequest#64867032::.ctor(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Verbose: 0 : [0620] Exiting WebRequest::Create()  -&gt; FtpWebRequest#64867032<br/>System.Net Verbose: 0 : [0620] FtpWebRequest#64867032::BeginGetResponse()<br/>System.Net Information: 0 : [0620] FtpWebRequest#64867032::BeginGetResponse(Methode = RETR.)<br/>System.Net.Sockets Verbose: 0 : [0620] Socket#51269976::Socket(InterNetwork#2)<br/>System.Net.Sockets Verbose: 0 : [0620] Exiting Socket#51269976::Socket() <br/>System.Net.Sockets Verbose: 0 : [0620] Socket#17940955::Socket(InterNetworkV6#23)<br/>System.Net.Sockets Verbose: 0 : [0620] Exiting Socket#17940955::Socket() <br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#64867032::BeginGetResponse() <br/>System.Net.Sockets Verbose: 0 : [0752] Socket#51269976::EndConnect(ConnectAsyncResult#7995840)<br/>System.Net.Sockets Error: 0 : [0752] Exception in the Socket#51269976::EndConnect - Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat 1.2.3.4:21<br/>A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll<br/>System.Net Verbose: 0 : [0752] FtpWebRequest#64867032::EndGetResponse()<br/>A first chance exception of type 'System.Net.WebException' occurred in System.dll<br/>System.Net Error: 0 : [0752] Exception in the FtpWebRequest#64867032::EndGetResponse - Die Verbindung mit dem Remoteserver kann nicht hergestellt werden.<br/>System.Net Error: 0 : [0752]    bei System.Net.FtpWebRequest.CheckError()<br/>   bei System.Net.FtpWebRequest.EndGetResponse(IAsyncResult asyncResult)<br/>A first chance exception of type 'System.Net.WebException' occurred in System.dll<br/>System.Net Verbose: 0 : [0752] Exiting FtpWebRequest#64867032::EndGetResponse() <br/>System.Net Verbose: 0 : [0620] WebRequest::Create(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Information: 0 : [0620] FtpWebRequest#59835590::.ctor(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Verbose: 0 : [0620] Exiting WebRequest::Create()  -&gt; FtpWebRequest#59835590<br/>System.Net Verbose: 0 : [0620] FtpWebRequest#59835590::BeginGetResponse()<br/>System.Net Information: 0 : [0620] FtpWebRequest#59835590::BeginGetResponse(Methode = RETR.)<br/>System.Net.Sockets Verbose: 0 : [0620] Socket#66433212::Socket(InterNetwork#2)<br/>System.Net.Sockets Verbose: 0 : [0620] Exiting Socket#66433212::Socket() <br/>System.Net.Sockets Verbose: 0 : [0620] Socket#42109742::Socket(InterNetworkV6#23)<br/>System.Net.Sockets Verbose: 0 : [0620] Exiting Socket#42109742::Socket() <br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#59835590::BeginGetResponse() <br/>System.Net.Sockets Verbose: 0 : [0752] Socket#66433212::EndConnect(ConnectAsyncResult#56251872)<br/>System.Net.Sockets Error: 0 : [0752] Exception in the Socket#66433212::EndConnect - Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat 1.2.3.4:21<br/>A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll<br/>System.Net Verbose: 0 : [0752] FtpWebRequest#59835590::EndGetResponse()<br/>A first chance exception of type 'System.Net.WebException' occurred in System.dll<br/>System.Net Error: 0 : [0752] Exception in the FtpWebRequest#59835590::EndGetResponse - Die Verbindung mit dem Remoteserver kann nicht hergestellt werden.<br/>System.Net Error: 0 : [0752]    bei System.Net.FtpWebRequest.CheckError()<br/>   bei System.Net.FtpWebRequest.EndGetResponse(IAsyncResult asyncResult)<br/>A first chance exception of type 'System.Net.WebException' occurred in System.dll<br/>System.Net Verbose: 0 : [0752] Exiting FtpWebRequest#59835590::EndGetResponse() <br/>System.Net Verbose: 0 : [0620] WebRequest::Create(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net.Sockets Verbose: 0 : [4672] Socket#42109742::Dispose()<br/>System.Net Information: 0 : [0620] FtpWebRequest#14556615::.ctor(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net.Sockets Verbose: 0 : [4672] Socket#17940955::Dispose()<br/>System.Net Verbose: 0 : [0620] Exiting WebRequest::Create()  -&gt; FtpWebRequest#14556615<br/>System.Net Verbose: 0 : [0620] FtpWebRequest#14556615::BeginGetResponse()<br/>System.Net Information: 0 : [0620] FtpWebRequest#14556615::BeginGetResponse(Methode = RETR.)<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#14556615::BeginGetResponse() <br/>System.Net Verbose: 0 : [0620] FtpWebRequest#14556615::Abort()<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#14556615::Abort() <br/>System.Net Verbose: 0 : [0620] WebRequest::Create(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Information: 0 : [0620] FtpWebRequest#1723863::.ctor(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Verbose: 0 : [0620] Exiting WebRequest::Create()  -&gt; FtpWebRequest#1723863<br/>System.Net Verbose: 0 : [0620] FtpWebRequest#1723863::BeginGetResponse()<br/>System.Net Information: 0 : [0620] FtpWebRequest#1723863::BeginGetResponse(Methode = RETR.)<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#1723863::BeginGetResponse() <br/>System.Net Verbose: 0 : [0620] FtpWebRequest#1723863::Abort()<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#1723863::Abort() <br/>System.Net Verbose: 0 : [0620] WebRequest::Create(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Information: 0 : [0620] FtpWebRequest#63782940::.ctor(<a href="ftp://1.2.3.4/abc"><span style="color:#0066dd">ftp://1.2.3.4/abc</span></a>)<br/>System.Net Verbose: 0 : [0620] Exiting WebRequest::Create()  -&gt; FtpWebRequest#63782940<br/>System.Net Verbose: 0 : [0620] FtpWebRequest#63782940::BeginGetResponse()<br/>System.Net Information: 0 : [0620] FtpWebRequest#63782940::BeginGetResponse(Methode = RETR.)<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#63782940::BeginGetResponse() <br/>System.Net Verbose: 0 : [0620] FtpWebRequest#63782940::Abort()<br/>System.Net Verbose: 0 : [0620] Exiting FtpWebRequest#63782940::Abort()Thu, 26 Nov 2009 11:30:39 Z2009-11-26T20:10:12Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/5a2beebf-7214-44c2-ad8a-ac2925becb1chttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/5a2beebf-7214-44c2-ad8a-ac2925becb1cEssPhttp://social.msdn.microsoft.com/Profile/en-US/?user=EssPSSL Excryption using Sockets over TCPHi, <div><br/></div> <div>We have a an existing application which uses System.Net.Sockets.Socket class to connect to a remote machine for data transfer and uses the TCP as the protocol. Now we have to encrypt this connection using SSLStream. How do we achieve this with the existing Socket class ?</div> <div><br/></div> <div>Thanks,</div> <div>EssP</div><hr class="sig">- SriThu, 26 Nov 2009 09:48:08 Z2009-11-26T19:13:06Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/9de248b7-fce4-4d94-b7e1-a8ad8201bdfchttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/9de248b7-fce4-4d94-b7e1-a8ad8201bdfcAnimalHomeMasterhttp://social.msdn.microsoft.com/Profile/en-US/?user=AnimalHomeMasterchecklist<span style="font-size:x-small"><span style="font-size:x-small"> <p>Hi<br/><br/>I am building an edit page.   So people have already checked boxes and  sumitted their choice.  That infor is stored in a database.   Now I want to let them change the selection.  <br/>The checkboxlist is populated by a database of choicies.   I also have another datebase where the customers choices are stored.  How do I make the users previous choices be check in the edit page.  I tried this but only one is checked I want up to three boxes checked<br/><br/>CheckBoxList1.SelectedValue =</p> </span></span> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Convert</span></span><span style="font-size:x-small">.ToString(Session[</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;SesCatGroupOne&quot;</span></span><span style="font-size:x-small">]);<span style="font-size:x-small"> <p>CheckBoxList1.SelectedValue =</p> </span></span> <p> </p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Convert</span></span><span style="font-size:x-small">.ToString(Session[</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;SesCatGroupTwo&quot;</span></span><span style="font-size:x-small">]);<span style="font-size:x-small"> <p>CheckBoxList1.SelectedValue =</p> </span></span> <p> </p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Convert</span></span><span style="font-size:x-small">.ToString(Session[</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;SesCatGroupThree&quot;</span></span><span style="font-size:x-small">]);<br/><br/>Thanks<br/><br/>Herb</span></p> </p> </p>Thu, 26 Nov 2009 04:17:42 Z2009-11-26T04:20:18Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/19aff870-426c-48b7-902e-2d6913360166http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/19aff870-426c-48b7-902e-2d6913360166cosbornehttp://social.msdn.microsoft.com/Profile/en-US/?user=cosborneHttpWebRequest CONNECT method - writing data after connectionI have successfully connected to a remote server through a proxy using HttpWebRequest with the Method property set to &quot;CONNECT&quot;. However it only seems possible to read data from the stream once connected, making the connection useless since I can't interact with the server that was the target of the CONNECT.<br/><br/>Sample code: <br/><br/> <div style="color:black;background-color:white"> <pre>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(<span style="color:#a31515">&quot;http://remote.server.name:999&quot;</span>);<br/>request.Method = WebRequestMethods.Http.Connect;<br/>request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;<br/>HttpWebResponse response = (HttpWebResponse)request.GetResponse();<br/>Stream stream = response.GetResponseStream();<br/><span style="color:blue">byte</span>[] input = <span style="color:blue">new</span> <span style="color:blue">byte</span>[10240];<br/>stream.Read(input, 0, input.Length);<br/><span style="color:blue">byte</span>[] output = GetData();<br/><span style="color:green">// I would like to be able to do the following, but a NotSupportedException is thrown (Message: &quot;The stream does not support writing.&quot;)<br/></span>stream.Write(output, 0, output.Length); </pre> </div> <br/>Looking at the data in &quot;input&quot; (from the snippet above), the connection to the remote server (i.e. tunnelled through the proxy using CONNECT), however at this point I ought to be able to access a 2-way data-stream, but the response stream is read only so there's no way to continue communication with the remote server.<br/><br/>The advantage of using HttpWebRequest is that it takes care of NTLM proxy authentication required for the particular proxy I'm connecting through which would be time consuming to re-implement using plain TCP sockets.<br/><br/>Is there any way to get a 2-way connection in this situation?Fri, 05 Jun 2009 07:03:44 Z2009-11-26T05:08:58Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/b45603ae-6403-451d-b1ad-0b5f827e7571http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/b45603ae-6403-451d-b1ad-0b5f827e7571Ay Xuhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ay%20Xubulk email send performance<p>Hello, I'm planning to develop a small bulk email sender program to send newsletters to around thousands customers.<br/>I did a google search and find code samples to use system.net.mail to send email, it works well.<br/>One question I want to know is:<br/>1) send to all customers at one time: put all email addresses into mail.to mailaddresscollection, and send out at once<br/>2) send to one customer at one time: put one email address in to mail.to, loop through whole customers<br/>which way has better performace?</p> <hr class=sig> AyFri, 20 Nov 2009 08:35:35 Z2009-11-25T23:37:36Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/3d066a6e-4ce4-4cd7-b7c9-a0687dc07eefhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/3d066a6e-4ce4-4cd7-b7c9-a0687dc07eefJoesoft11ahttp://social.msdn.microsoft.com/Profile/en-US/?user=Joesoft11aNet Sockets with MultiThreading in VC#I downloaded a pdf file that has a sample of setting up a Socket Server and Client. The code works with no problems. The problem I'm having is that it refers to a 'table.txt' file that goes in the DNS Server root folder when the server is running. Well it doesn't tell me what this file is or what does in it. When I connect to the server. <br/> And I type in Hello. It does unresolved . <br/> <br/> any way theres no Name or company that's taking credit for this file. Here's the link for it off my web site.<br/> http://toppersbbs.dtdns.net/vip/socket_programming.pdf<br/> <br/> can any one tell me what that file is and what's it for.<br/> <br/> Thanks<br/> Joe<br/><hr class="sig">Toppers BBS http://toppersbbs.dtdns.net Mon, 23 Nov 2009 04:35:44 Z2009-11-25T21:55:15Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/4e8956a3-7138-49f6-bf82-dda08c7d2c91http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/4e8956a3-7138-49f6-bf82-dda08c7d2c91Korderhttp://social.msdn.microsoft.com/Profile/en-US/?user=KorderAre Socket.SendAsync and ReceiveAsync threadsafe<p>In a multithreading enviroment, is safe to call SendAsync multiple times from different Threads? I know that i must use a different SocketAsyncEventArgs Event for every call and i can not be sure that the packets arrive in order, but do they at least arrive as a complete packet? So will packet A arrive before packet B (or B before A, doesn’t matter), or is it possible for B to be in the middle of A?</p> <p>What happens if you use ReceiveAsync with multiple packets waiting for receiving would also be intereesting. I don’t mean more packets in the stream waiting to be read, but receiving another packet while ReceiveAsync is running.</p> <p>Since TCP is full duplex, i assume that sending and receiving at the same time are no problem.</p>Wed, 25 Nov 2009 20:06:07 Z2009-11-27T14:19:13Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0390da9d-49b3-4510-88a1-5c9cdf61661fhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0390da9d-49b3-4510-88a1-5c9cdf61661fcyrix86http://social.msdn.microsoft.com/Profile/en-US/?user=cyrix86Programmatically login to msdn forums using web request post?<p>Is this possible? I'm new to using the webrequest class</p>Tue, 24 Nov 2009 19:19:15 Z2009-11-25T14:38:07Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/fa0f6ea6-727c-4eac-8ff9-d5fe0427fc3chttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/fa0f6ea6-727c-4eac-8ff9-d5fe0427fc3cnevviinhttp://social.msdn.microsoft.com/Profile/en-US/?user=nevviinlong time to get response from server? &lt;!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:&quot;&quot;; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:&quot;Times New Roman&quot;; mso-fareast-font-family:&quot;Times New Roman&quot;;} @page Section1 {size:8.5in 11.0in; margin:1.0in .5in 1.0in .5in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --&gt; <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>    </span> <span style="color:blue">Dim</span> nwStream <span style="color:blue">As</span> NetworkStream</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">Private</span> <span style="font-size:10pt;font-family:'Courier New'"> reader <span style="color:blue">As</span> StreamReader = <span style="color:blue">Nothing</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue"> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">Function</span> <span style="font-size:10pt;font-family:'Courier New'"> GetMessage(<span style="color:blue">ByVal</span> msgindex <span style="color:blue">As</span> <span style="color:blue">Integer</span> ) <span style="color:blue">As</span> <span style="color:blue">String</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Dim</span> tmpString <span style="color:blue">As</span> <span style="color:blue">String</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Dim</span> Data <span style="color:blue">As</span> <span style="color:blue">String</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Dim</span> SzData() <span style="color:blue">As</span> <span style="color:blue">Byte</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Dim</span> msg <span style="color:blue">As</span> <span style="color:blue">String</span> = <span style="color:#a31515">&quot;&quot;</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>    </span> <span>    </span> <span style="color:blue">Try</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> Data = <span style="color:#a31515">&quot;RETR &quot;</span> &amp; msgindex.ToString &amp; vbCrLf</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> SzData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> <span style="color:green">'sslstream.Write(SzData, 0, SzData.Length)</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> nwStream.Write(SzData, 0, SzData.Length)</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>       </span> <span>     </span> tmpString = reader.ReadLine()</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> <span style="color:blue">If</span> tmpString.Substring(0, 4) &lt;&gt; <span style="color:#a31515">&quot;-ERR&quot;</span> <span style="color:blue">Then</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>                </span> <span style="color:blue">While</span> (tmpString &lt;&gt; <span style="color:#a31515">&quot;.&quot;</span> )</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>                    </span> msg = msg &amp; tmpString &amp; vbCrLf</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>                    </span> tmpString = reader.ReadLine</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>                </span> <span style="color:blue">End</span> <span style="color:blue">While</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> <span style="color:blue">End</span> <span style="color:blue">If</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Catch</span> ex <span style="color:blue">As</span> InvalidOperationException</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>            </span> appendFile(strErrPath, <span style="color:#a31515">&quot;Message Retrival Failed: in fun<span>  </span> POP GetMessage() &quot;</span> &amp; vbCrLf &amp; ex.ToString())</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">End</span> <span style="color:blue">Try</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>        </span> <span style="color:blue">Return</span> msg</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New'"><span>    </span> <span style="color:blue">End</span> <span style="color:blue">Function</span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue"> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">Hi, all . thanks for the help and<span>  </span> support. Here I am facing an issue. <br/> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">I have written an vb.net application to fetch mails from a popserver and push to a database.I am using the Getmessage function to retrieve message from the popserver .</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">I am sending the command through the </span> <span style="font-size:10pt;font-family:'Courier New'">nwStream (networkstream object). <span style="color:blue">And am reading the response using a stream reader. </span> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue"> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">The application should be running 24/7 with out stoping.The problem here I am facing is when I send a retrieval command suppose<span>  </span> first mail from server .<span>  </span> Retr 1. Some times it’s taking too much time to get respose or some times because of the long response time, the applications got hanged. so I want to stop fetching after a fixed time suppose if 40 secconds or 50 and<span>  </span> the control has to get out of the function so that the application can go for other fetch .Or if anybody has other good suggestions please help me.</span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue"> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">I am new to this network programming. Can anybody help me to fix this issue <br/> </span></p> <p class=MsoNormal><span style="font-size:10pt;font-family:'Courier New';color:blue">thanks &amp; regards<br/> </span></p><hr class="sig">Thanks &amp; Regards http://www.keralapavilion.com/Sat, 14 Nov 2009 09:23:00 Z2009-11-25T14:37:22Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/b08e14fd-e6af-4375-a646-ae4a231505c3http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/b08e14fd-e6af-4375-a646-ae4a231505c3emacariehttp://social.msdn.microsoft.com/Profile/en-US/?user=emacarieHow to make HttpListenerResponse work with multiple cookies ?Hi, <div><br/></div> <div>  I am currently developing on .NET framework 3.5 SP1 (version 3053)</div> <div>  I cannot make HttpListenerResponse work with multiple cookies.  When I add multiple cookies in one request HttpListenerResponse should output separate Set-Cookie headers for each cookie.  Instead it combines them together in one comma separated Set-Cookie header which does not work.</div> <div>  According to <a href="http://support.microsoft.com/kb/933905">http://support.microsoft.com/kb/933905</a> it should have been fixed in .NET 2.0 SP1, but it does not look that way.</div> <div>  The following code illustrates this problem.  Only the first one of the below cookies will be successfully registered:</div> <div>  </div> <div>   <pre lang="x-c#">static void Main(string[] args) { string[] prefixes = { &quot;http://+:8080/&quot; }; SimpleListenerExample(prefixes); } public static void SimpleListenerExample(string[] prefixes) { if (!HttpListener.IsSupported) { Console.WriteLine(&quot;Windows XP SP2 or Server 2003 is required to use the HttpListener class.&quot;); return; } if (prefixes == null || prefixes.Length == 0) throw new ArgumentException(&quot;prefixes&quot;); HttpListener listener = new HttpListener(); foreach (string s in prefixes) { listener.Prefixes.Add(s); } listener.Start(); Console.WriteLine(&quot;Listening...&quot;); while (true) { HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; Console.WriteLine(&quot;Received Request for: &quot; + request.Url.AbsoluteUri); HttpListenerResponse response = context.Response; string responseString = &quot;&lt;HTML&gt;&lt;BODY&gt; Hello world!&lt;/BODY&gt;&lt;/HTML&gt;&quot;; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; Cookie myCookie = new Cookie(&quot;MyCookie&quot;, &quot;Url is hi=dd,: &quot; + context.Request.Url.AbsoluteUri, &quot;/&quot;); myCookie.HttpOnly = true; myCookie.Version = 1; response.SetCookie(myCookie); Cookie myCookie2 = new Cookie(&quot;MyCookie2&quot;, &quot;Url is: &quot; + context.Request.Url.AbsoluteUri, &quot;/&quot;); myCookie2.HttpOnly = true; myCookie2.Version = 1; response.SetCookie(myCookie2); Cookie myCookie3 = new Cookie(&quot;MyCookie3&quot;, &quot;Url is: &quot; + context.Request.Url.AbsoluteUri, &quot;/&quot;); //myCookie3.HttpOnly = true; myCookie3.Version = 1; response.SetCookie(myCookie3); System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); } //listener.Stop(); }</pre> <br/></div> <div><br/></div> <div>  Any help would be very appreciated.</div>Wed, 25 Nov 2009 00:01:00 Z2009-11-25T00:01:00Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2681d2d0-28b0-4f6f-bb7d-fed47af12ae3http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2681d2d0-28b0-4f6f-bb7d-fed47af12ae3Ran Qinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ran%20Qinkeepalive timeout valueHi:<br/>   Does anyone here know how long .Net Framework 2.0 will keep Http1.1 connection alive before it closes it out.<br/>I only know IE will close it out after a connection is idle for 60 seconds from this article: <a href="http://support.microsoft.com/kb/813827">http://support.microsoft.com/kb/813827</a><br/>I also know .Net Framework use 100 seconds by default to time out a connection, but that value is used to close out active connection that takes too long to finish. Is this value also used to time out idle connection when keep-alive=true?<br/>   Any help is appreciated!<br/><br/>Tue, 24 Nov 2009 20:41:13 Z2009-11-24T20:41:14Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/d40aa921-d4e4-47a7-a077-aba335103920http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/d40aa921-d4e4-47a7-a077-aba335103920hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzsome help with meaning/purpose of ManualResetEvent variables in my socket code.Evaluating JUST the ManualResetEvents, as I am only beginning to understand them:<br/> 1. <strong>ConnectDone.Reset()</strong>   - <strong>the doors are closed</strong>, (non-signaled)  but what does that mean?  Which door is closed?  Some connect thread?<br/> 2.  <strong>ConnectDone.WaitOne()</strong> - the connect process commences. <br/> 3.  <strong>ConnectDone.Set()</strong>         -  <strong>the door is open</strong> now.  Does that mean THE thread used for the connect process is available again.  Was this a thread taken from some threadpool temporarily?<br/> 4  sendDone.Set()        -   the door is open.  <br/><br/>What I see in my code is I have no <strong>sendDone.Reset()</strong> nor do I have <strong>sendDone.WaitOne()<br/></strong>Also, I  have absolutely <strong>no ManualResetEvent</strong> variables/flags/<strong>signals</strong> in my code anywhere for <strong>Receive()</strong> and <strong>ReceiveCallBack();</strong>  <br/>As you can see, I don't know what I'm doing (but I do want to learn !!)  Thank you for any help.  greg<br/> <div style="color:black;background-color:white"><br/> <pre lang="x-c#"> private static ManualResetEvent connectDone = new ManualResetEvent(false); //?? private static ManualResetEvent receiveDone = new ManualResetEvent(false); //?? private static ManualResetEvent sendDone = new ManualResetEvent(false); //?? public static void BeginConnect(string host, int port) { connectDone.Reset(); connectDone.WaitOne(); } public static void ConnectCallback(IAsyncResult ar) { connectDone.Set(); } private static void SendCallback(IAsyncResult ar) { sendDone.Set(); } private static void ReceiveCallback(IAsyncResult ar) { private static ManualResetEvent connectDone = new ManualResetEvent(false); //?? private static ManualResetEvent receiveDone = new ManualResetEvent(false); //?? private static ManualResetEvent sendDone = new ManualResetEvent(false); //?? public static void BeginConnect(string host, int port) { connectDone.Reset(); connectDone.WaitOne(); } public static void ConnectCallback(IAsyncResult ar) { connectDone.Set(); } private static void SendCallback(IAsyncResult ar) { sendDone.Set(); } private static void ReceiveCallback(IAsyncResult ar) { }</pre> <br/></div>Tue, 24 Nov 2009 20:31:58 Z2009-11-24T20:31:58Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/1c804614-d928-4bb9-af2b-55693533cb40http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/1c804614-d928-4bb9-af2b-55693533cb40hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzI'm trying to debug my EndReceive Callback and see what the host just sent back to 'me', the client.<p>Code <br/></p> <pre lang="x-c#"> private static void ReceiveCallback(IAsyncResult ar) { try { lock (syncObj) { // disable the timer, since the read callback fired within timeout timerForTimeOut.Change(125, Timeout.Infinite); } StateObject state = (StateObject)ar.AsyncState; Socket client = state.workSocket; int bytesRead = client.EndReceive(ar); if (bytesRead &gt; 0) { state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); if (state != null) { Console.WriteLine(&quot;bytes appended to state object sb = &quot; + state.sb.ToString() + &quot;end of string&quot;); client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, new AsyncCallback(ReceiveCallback), state); } client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, new AsyncCallback(ReceiveCallback), state); } else { Console.WriteLine(&quot;ar object is null in ReceiveCallback()after timer call&quot;); } } catch (Exception ex) { Console.Write(&quot;ReceiveCallback = &quot; + ex.ToString()); } }</pre>Tue, 24 Nov 2009 18:06:53 Z2009-11-24T18:06:53Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/68b7119b-3f86-4043-9ca3-d67f62674876http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/68b7119b-3f86-4043-9ca3-d67f62674876NicoleVT2000http://social.msdn.microsoft.com/Profile/en-US/?user=NicoleVT2000Establishing a database connection using Putty to tunnel over SSH<span class=font8pt>I currently have an ASP.NET web application that is using a MySQL database as the source data. I would like to connect to this database using the standard MySQL listening port of 3306 and tunnel the database connection over SSH (Port 22). I have Putty on my Web server and will configure Putty to do Port Redirection (3306 &gt; 22 &gt; 3306). I would like my web application to first open the Putty connection (somehow have my web application pass the credentials to the server via Putty) which would establish an SSH connection to the distant server. Once that SSH connection is established, I would then establish a standard MySQL database connection using a connection string. I would prefer not to leave the SSH connection open all the time and want Logi to handle both the SSH and database connection calls only when it is needed. This methodology of tunneling a database connection over SSH is not MySQL specific and could be used to securely tunnel any database connection. Has anyone done anything like this and if so could you provide me with how you had the web application establish these connection calls? <br/></span>Tue, 24 Nov 2009 17:38:05 Z2009-11-24T17:38:07Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0be85fa8-0328-4798-a5c9-09f8366e54e4http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0be85fa8-0328-4798-a5c9-09f8366e54e4hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzTCP Sequence Diagram question for my .Net sockets project.<a href="http://alturl.com/nd3o">http://alturl.com/nd3o</a>   is the image that shows my diagram.  (Windows Live SkyDrive is the hosting environment)<br/><br/><strong>Shouldn't there an ACK between the FIN,ACK flags from client to host then host to client?</strong> <br/><br/>I'm trying to figure out what I need to do with my Event-Based Asynchronous Pattern based on  (<a href="http://msdn.microsoft.com/en-us/library/bbx2eya8(VS.71).aspx">http://msdn.microsoft.com/en-us/library/bbx2eya8(VS.71).aspx</a> )  to get the TCP communication working correctly.<br/><br/>My previous posts including code have pointed perhaps to my incorrect understanding of the use of System.Threading.Timer which I'm employing to set a 125 millisecond timeout limit on the transactions between client and host.<br/><br/>Thank you for any help.  If I'm not asking the right question, please advise.<br/>Greg<br/><br/><br/><br/>Tue, 24 Nov 2009 16:16:52 Z2009-11-24T16:16:52Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/264a4eaf-504a-487f-b155-fd7432ac94a0http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/264a4eaf-504a-487f-b155-fd7432ac94a0hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzSystem.ObjectDisposedException: Cannot access a disposed object.<p>I'm hightlighting in red the two lines below where this occurs. I'm not sure why, given my current codebase, that these errors are occurring. The lines where the errors occur and their order is.<br/>1.    int bytesRead = client.EndReceive(ar);      in ReceiveCallBack()  and<br/>2.    client.Shutdown(SocketShutdown.Both);       in DeviceCommunicationTimeOut</p> <div style="color:black;background-color:white"> <pre> <span style="color:blue">public</span> <span style="color:blue">class</span> StateObject { <span style="color:blue">public</span> Socket workSocket = <span style="color:blue">null</span>; <span style="color:blue">public</span> <span style="color:blue">const</span> <span style="color:blue">int</span> BufferSizeForReceive = 2400; <span style="color:blue">public</span> <span style="color:blue">byte</span>[] buffer = <span style="color:blue">new</span> <span style="color:blue">byte</span>[BufferSizeForReceive]; <span style="color:blue">public</span> StringBuilder sb = <span style="color:blue">new</span> StringBuilder(); <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">byte</span>[] toSocket; } <span style="color:blue">public</span> <span style="color:blue">partial</span> <span style="color:blue">class</span> Form1 : Form { <span style="color:blue">private</span> <span style="color:blue">static</span> System.Threading.Timer timerForTimeOut = <span style="color:blue">null</span>; <span style="color:green">//one shot </span> <span style="color:blue">private</span> <span style="color:blue">static</span> Object syncObj = <span style="color:blue">new</span> Object(); <span style="color:green">//Lock when receiving data or TimeOut called</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent connectDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent receiveDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> ManualResetEvent sendDone = <span style="color:blue">new</span> ManualResetEvent(<span style="color:blue">false</span>); <span style="color:green">//??</span> <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">byte</span>[] toSocket; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> response; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> softwareVersionFromDevice; <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">string</span> host = <span style="color:#a31515">&quot;10.0.110.35&quot;</span>; <span style="color:blue">private</span> <span style="color:blue">static</span> Int32 port = 50000; <span style="color:blue">public</span> Form1() { InitializeComponent(); toSocket = <span style="color:blue">new</span> <span style="color:blue">byte</span>[7]; toSocket[0] = 2; <span style="color:green">//msgID</span> toSocket[1] = 0; <span style="color:green">//status</span> toSocket[2] = 0; <span style="color:green">//data lehgth</span> toSocket[3] = 0; toSocket[4] = 0; <span style="color:green">//seq #</span> toSocket[5] = 1; } <span style="color:blue">private</span> <span style="color:blue">void</span> button1_Click(<span style="color:blue">object</span> sender, EventArgs e) { BeginConnect(host, port); } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">void</span> BeginConnect(<span style="color:blue">string</span> host, <span style="color:blue">int</span> port) { Socket s = <span style="color:blue">new</span> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); connectDone.Reset(); s.BeginConnect(host, port, <span style="color:blue">new</span> AsyncCallback(ConnectCallback), s); connectDone.WaitOne(); } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">void</span> ConnectCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; client.EndConnect(ar); connectDone.Set(); <span style="color:blue">if</span> (timerForTimeOut == <span style="color:blue">null</span>) timerForTimeOut = <span style="color:blue">new</span> System.Threading.Timer(DeviceCommunicationTimeOut, client, 125, 125); Send(client); } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> DeviceCommunicationTimeOut(<span style="color:blue">object</span> state) { Socket client = (Socket)state; <span style="color:blue">lock</span> (syncObj) { <span style="color:green">// timed out. close and shutdown socket</span> <span style="font-size:medium;color:#ff0000"> client.Shutdown(SocketShutdown.Both); </span> client.Close(); } } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> Send(Socket client) { client.BeginSend(toSocket, 0, toSocket.Length, SocketFlags.None, <span style="color:blue">new</span> AsyncCallback(SendCallback), client); } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> SendCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; <span style="color:blue">int</span> bytesSent = client.EndSend(ar); sendDone.Set(); Receive(client); } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> Receive(Socket client) { StateObject state = <span style="color:blue">new</span> StateObject(); state.workSocket = client; client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, <span style="color:blue">new</span> AsyncCallback(ReceiveCallback), state); } <span style="color:blue">private</span> <span style="color:blue">static</span> <span style="color:blue">void</span> ReceiveCallback(IAsyncResult ar) { <span style="color:blue">if</span> (ar != <span style="color:blue">null</span>) { <span style="color:blue">lock</span> (syncObj) { <span style="color:green">// disable the timer, since the read callback fired within timeout</span> timerForTimeOut.Change(125, 10000); <span style="color:green">// Timeout.Infinite</span> } StateObject state = (StateObject)ar.AsyncState; Socket client = state.workSocket; <span style="color:blue">if</span> (ar != <span style="color:blue">null</span>) { <span style="color:blue">int</span><span style="font-size:large;color:#ff0000"> bytesRead = client.EndReceive(ar); </span> <span style="color:blue">if</span> (bytesRead &gt; 0) { state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); client.BeginReceive(state.buffer, 0, StateObject.BufferSizeForReceive, 0, <span style="color:blue">new</span> AsyncCallback(ReceiveCallback), state); } <span style="color:blue">else</span> { <span style="color:blue">if</span> (state.sb.Length &gt; 1) { response = state.sb.ToString(); } receiveDone.Set(); } } <span style="color:blue">else</span> <span style="color:green">//ar is null</span> { Console.WriteLine(<span style="color:#a31515">&quot;ar object is null in ReceiveCallback()after timer call&quot;</span>); } Console.WriteLine(<span style="color:#a31515">&quot;ReceiveCallback EndReceive&quot;</span>); } <span style="color:blue">else</span> { Console.WriteLine(<span style="color:#a31515">&quot;The Socket on ReceiveCallBack is NULL&quot;</span>); } } } </pre> </div>Mon, 23 Nov 2009 20:49:46 Z2009-11-24T14:42:36Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/063b21ee-7c12-4c44-9fdc-ffcc1c15e0f3http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/063b21ee-7c12-4c44-9fdc-ffcc1c15e0f3csalle01http://social.msdn.microsoft.com/Profile/en-US/?user=csalle01WebClient UploadData gives 400 Bad Request error when I upload file with special charactersI am trying to upload documents to a sharepoint server.  I am able to do it successfully if the file name does not have special characters. However, if for example, an &amp; exists in the file name (file&amp;name.txt) i get a 400 Bad Request error returned from the UploadData method. <br/> <br/> Here is my code:<br/> <br/> WebClient wcUpload = new WebClient();<br/> wcUpload.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;<br/> wcUpload.Encoding = System.Text.Encoding.ASCII;<br/> <br/> /* url is passed into my upload method */<br/> url = string fileName = HttpUtility.UrlEncode(url);<br/> <br/> try<br/> {<br/>   wcUpload.UploadData(url, &quot;PUT&quot;, fileByteArray);<br/> }<br/> catch (WebException ex)<br/> {<br/>    throw;<br/>  } <br/> <br/> I would really appreciate some help<br/> ThanksFri, 06 Nov 2009 18:25:19 Z2009-11-24T14:34:15Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/3a53abb1-3b77-4b91-834f-1767b42f0b11http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/3a53abb1-3b77-4b91-834f-1767b42f0b11Sallyherehttp://social.msdn.microsoft.com/Profile/en-US/?user=SallyhereMailMessages(System.Net.Mail) - Save<span style="font-family:Courier New;font-size:x-small">I am saving Mailmessages in .eml but I want it in .msg<br/><br/>string</span><span style="font-family:'Courier New';font-size:10pt"><span style="color:#000000"> tempName = </span><span style="color:#a31515">&quot;TMReport&quot;</span><span style="color:#000000"> + </span><span style="color:#a31515">&quot;_&quot;</span><span style="color:#000000"> + </span><span style="color:#2b91af">DateTime</span><span style="color:#000000">.Now.ToShortDateString().Replace(</span><span style="color:#a31515">&quot;/&quot;</span><span style="color:#000000">, </span><span style="color:#a31515">&quot;_&quot;</span><span style="color:#000000">) + </span><span style="color:#a31515">&quot; &quot;</span><span style="color:#000000"> + </span><span style="color:#2b91af">DateTime</span><span style="color:#000000">.Now.ToLongTimeString().Replace(</span><span style="color:#a31515">&quot;:&quot;</span><span style="color:#000000">, </span><span style="color:#a31515">&quot;-&quot;</span><span style="color:#000000">);</span></span> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Courier New';font-size:10pt"><span style="color:green">//string tempfilename = System.IO.Path.GetTempPath() + tempName + &quot;.msg&quot;;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Courier New';font-size:10pt"><span style="color:blue">string</span><span style="color:#000000"> tempfilename = System.IO.</span><span style="color:#2b91af">Path</span><span style="color:#000000">.GetTempPath() + tempName + </span><span style="color:#a31515">&quot;.eml&quot;</span><span style="color:#000000">;<br/></span></span><span style="font-family:'Courier New';font-size:10pt"><span style="color:#000000">IDfile = Save(mailMessage, tempfilename);</span></span><br/><br/><br/>public</p> <span class=code-keyword>static</span> <span class=code-keyword>void</span> Save(<span class=code-keyword>this</span> MailMessage Message, <span class=code-keyword>string</span> FileName)<br/>    {<br/>        Assembly assembly = <span class=code-keyword>typeof</span>(SmtpClient).Assembly;<br/>        Type _mailWriterType =  assembly.GetType(<span class=code-string>&quot;</span><span class=code-string>System.Net.Mail.MailWriter&quot;</span>);<br/>        <br/><span class=code-keyword>        using</span> (FileStream _fileStream = <span class=code-keyword>new</span> FileStream(FileName, FileMode.Create)){<br/>            <span class=code-comment>//</span><span class=code-comment> Get reflection info for MailWriter contructor</span><br/>            ConstructorInfo _mailWriterContructor =_mailWriterType.GetConstructor(<br/>                    BindingFlags.Instance | BindingFlags.NonPublic,<br/>                    <span class=code-keyword>null</span>,<br/>                    <span class=code-keyword>new</span> Type[] { <span class=code-keyword>typeof</span>(Stream) }, <br/>                    <span class=code-keyword>null</span>);<br/><br/>            <span class=code-comment>//</span><span class=code-comment> Construct MailWriter object with our FileStream</span><br/>            <span class=code-keyword>object</span> _mailWriter = _mailWriterContructor.Invoke(<span class=code-keyword>new</span> <span class=code-keyword>object</span>[] { _fileStream });<br/><br/>            <span class=code-comment>//</span><span class=code-comment> Get reflection info for Send() method on MailMessage</span><br/>            MethodInfo _sendMethod = <span class=code-keyword>typeof</span>(MailMessage).GetMethod(<br/><span class=code-string>                                                                                 &quot;</span><span class=code-string>Send&quot;</span>,<br/>                                                                                  BindingFlags.Instance |  BindingFlags.NonPublic);<br/><br/>            <span class=code-comment>//</span><span class=code-comment> Call method passing in MailWriter</span><br/>            _sendMethod.Invoke(<br/>                Message,<br/>                BindingFlags.Instance | BindingFlags.NonPublic,<br/>                <span class=code-keyword>null</span>,<br/>                <span class=code-keyword>new</span> <span class=code-keyword>object</span>[] { _mailWriter, <span class=code-keyword>true</span> },<br/>                <span class=code-keyword>null</span>);<br/><br/>            <span class=code-comment>//</span><span class=code-comment> Finally get reflection info for Close() method on our MailWriter</span><br/>            MethodInfo _closeMethod =  _mailWriter.GetType().GetMethod(<br/>                   <span class=code-string>&quot;</span><span class=code-string>Close&quot;</span>,<br/>                    BindingFlags.Instance | BindingFlags.NonPublic);<br/><br/>            <span class=code-comment>//</span><span class=code-comment> Call close method</span><br/>            _closeMethod.Invoke(<br/>                _mailWriter,<br/>                BindingFlags.Instance | BindingFlags.NonPublic,<br/>                <span class=code-keyword>null</span>,<br/>                <span class=code-keyword>new</span> <span class=code-keyword>object</span>[] { },<br/>                <span class=code-keyword>null</span>);<br/>        }<br/>    }<br/>Mon, 23 Nov 2009 19:34:09 Z2009-11-26T08:34:41Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/ac8ecec6-1e1a-4808-8dbe-475d23d16942http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/ac8ecec6-1e1a-4808-8dbe-475d23d16942Brrthttp://social.msdn.microsoft.com/Profile/en-US/?user=BrrtSockets.Networkstream.read: no exception generated if client disconnects because its network failsI'm adding exception handling to my TCP server project. I've been able to catch almost all exceptions in networkstream.read except for 1 and I don't know how to proceed.<br/> Below are a few snippets of what I did. The thing is that stream.read doesn't throw an exception when the clients network drops out.<br/> <br/> What I did to test:<br/> -Run this server<br/> -Run a client on a laptop with WiFi and connect to this server<br/> -send some commands --&gt; all is going well<br/> -disconnect the client they correct way --&gt; all is going well, exception is catched beautifully<br/> -run client again<br/> -disable Wifi on the laptop<br/> --&gt; There's no exception thrown in!<br/> -enable wifi again and try to reconnect<br/> --&gt; no way to reconnect because the server is this trying to read previous stuff.<br/> <br/> I know I could try to put all this in a multithreading server, but isn't there any other way to detect if the client disconnects because his network failed/dropped out?<br/> <br/> <pre lang=x-vbnet>dim listener As Sockets.TcpListener dim client As Sockets.TcpClient Dim stream As Sockets.NetworkStream = client.GetStream listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, port) client = listener.AcceptTcpClient While stream.CanRead Try i = stream.Read(bytes, 0, bytes.Length) Catch ex As Exception i = 0 'reset to prevent partial data being stuck<br/> 'this exception doesn't occur when clients network drops!!!!! <br/>   End Try data = Encoding.UTF8.GetString(bytes, 0, i) If data.Length &gt; 0 Then processData(data) Else 'data = 0 which isn't very good, so send error to the client and see if it's still connected Try stream.Write(System.Text.Encoding.UTF8.GetBytes(ERRORMESSAGE), 0, System.Text.Encoding.UTF8.GetBytes(ERRORMESSAGE).Length) Catch ex As Exception If client.Connected Then 'the client is still connected Else 'the client is disconnected so stop reading and wait untill another client connects Exit While End If End Try End If End While </pre>Sun, 22 Nov 2009 22:46:12 Z2009-11-24T20:54:06Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/5da04ef6-bf59-4435-af28-7f9e37281c0bhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/5da04ef6-bf59-4435-af28-7f9e37281c0bTheDaywalkerhttp://social.msdn.microsoft.com/Profile/en-US/?user=TheDaywalkerMultithreaded Sockets (Visual Basic 2008)<p>Hi, I'm an old Visual Basic 6 developer and now I want to switch to .NET but I'm having difficulties on sockets since I'm used to VB6's Winsock object.<br/>I have my own server &amp; client program which run on a specific port. I 've more than 130 clients. For making myself a little bit more clear, I must say it's pretty like an IRC application, both the server and client side. Clients will stay connected all the day and there will be data tansfer over the connection continuously, just like IRC servers and mIRC do.<br/>In that regard, as much as I've learned, Sockets in .NET dont have Events, which I need most. And the only way is to use multithreaded sockets. Althought all my searches, I could not find any good and detailed tutorial or an example or even a book that explains how to use them.<br/><br/>I simply need to listen on a specific port and accept every incoming connection (as I guess) into a new thread, and be able to use events like onConnect, onClose, onDataArrival and onError for each thread seperately. <br/><br/>Any advices on detailed tutorials or examples or books would be really great.</p>Sat, 21 Nov 2009 06:20:06 Z2009-11-21T12:14:50Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/231885dc-3c18-4363-8202-2d04c90b89e8http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/231885dc-3c18-4363-8202-2d04c90b89e8princess_980http://social.msdn.microsoft.com/Profile/en-US/?user=princess_980generat table from class diagramHi,<br/>How can I generate table database from class diagram in .net?<br/>Can I generate database from class diagram in rational roseSat, 21 Nov 2009 08:10:37 Z2009-11-21T08:10:37Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/094ffeeb-c2ba-479c-9e86-07fe4ac52ee8http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/094ffeeb-c2ba-479c-9e86-07fe4ac52ee8aruizmoraleshttp://social.msdn.microsoft.com/Profile/en-US/?user=aruizmoralesGetting localmachine credentials - HelpHello, <br/><br/>I'm running a machine that is joined to a Domain. I have a win32 application that prompts me for my credentials each time I run it. I'm trying to use the Sysrem.Window.Automation namespace to automate this step. I can explicitly get the AutomationElement and set my credentials in the password field. However, since the code will be used by others within my group I am trying to get the logged in accounts credentials (ie. If I'm Domain/MyUsername is on the machine, then retrieve my Credentials and set them on the password field). That way, when someone see's the code they can reuse it without having my password stored somewhere. They can also run it with his/her own credentials.<br/><br/><br/>I'm trying to use the following:<br/><br/><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="font-size:x-small"> cred = System.Net.</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">CredentialCache</span></span><span style="font-size:x-small">.DefaultNetworkCredentials<br/><br/>then, cred.Password<br/><br/>but I get a null reference unless I explicitly set it before. <br/><br/>I also looked into ICredentialByHost but am unsure on how to implement it.<br/><br/>All I need to do is somehow get the credentials used by the user who is logged in into the machien. Can someone help?<br/><br/>Thanks,<br/>Angel</span></p>Fri, 20 Nov 2009 21:29:09 Z2009-11-21T02:39:16Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e8299a25-67a7-4e19-b4d3-117f95391558http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e8299a25-67a7-4e19-b4d3-117f95391558Dave Harveyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Dave%20HarveyWhy does SslStream see to ignore the RequireClientAuthentication flag?<p>I am trying to use certificate based client authentication using an SslStream object, using the code below (which calls itself), but the client certificate doesn't seem to get used or if itis used, it is not available to the server.  Points to note:<br/><br/><br/>1) We are offering the certificate for both the server and client (the same is used for both, but behaviour is the same if they are different)<br/>2) The RequireClientAuthentication flag in the AuthenticateAsServer is <strong>true</strong> <br/>3) Despite this, the RemoteCertificate property of the server's ssl_server object is still null after negotiation :-(<br/>4) The value passed to <span style="font-family:Courier New">CertificateValidationCallback</span> by the server is also null<br/><br/>What am I doing wrong?  Or is there a bug in the SslStream negotiation?<br/><br/>Dave</p> <span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System.Windows.Forms;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System.Net.Sockets;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System.Net.Security;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System.Threading;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">using</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> System.Security.Cryptography.X509Certificates;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;color:blue;font-family:'Courier New'">namespace</span><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> WindowsFormsApplication9</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000">{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">    </span></span><span style="color:blue">public</span><span style="color:#000000"> </span><span style="color:blue">partial</span><span style="color:#000000"> </span><span style="color:blue">class</span><span style="color:#000000"> </span><span style="color:#2b91af">Form1</span><span style="color:#000000"> : </span><span style="color:#2b91af">Form</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">    </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">        </span></span><span style="color:#2b91af">X509Certificate2</span><span style="color:#000000"> Certificate = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">X509Certificate2</span><span style="color:#000000">(</span><span style="color:#a31515">@&quot;C:\MyCert.pfx&quot;</span><span style="color:#000000">);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">        </span></span><span style="color:blue">public</span><span style="color:#000000"> Form1()</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>InitializeComponent();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">ThreadPool</span><span style="color:#000000">.QueueUserWorkItem(Listen);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>}</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">        </span></span><span style="color:blue">public</span><span style="color:#000000"> </span><span style="color:blue">bool</span><span style="color:#000000"> CertificateValidationCallback(</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">Object</span><span style="color:#000000"> sender,</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">X509Certificate</span><span style="color:#000000"> certificate,</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">X509Chain</span><span style="color:#000000"> chain,</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">SslPolicyErrors</span><span style="color:#000000"> sslPolicyErrors</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>)</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:blue">return</span><span style="color:#000000"> </span><span style="color:blue">true</span><span style="color:#000000">;</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>}<span style="">        </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">        </span></span><span style="color:blue">private</span><span style="color:#000000"> </span><span style="color:blue">void</span><span style="color:#000000"> button1_Click(</span><span style="color:blue">object</span><span style="color:#000000"> sender, </span><span style="color:#2b91af">EventArgs</span><span style="color:#000000"> e)</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">TcpClient</span><span style="color:#000000"> t = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">TcpClient</span><span style="color:#000000">(</span><span style="color:#a31515">&quot;localhost&quot;</span><span style="color:#000000">, 9999);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">X509CertificateCollection</span><span style="color:#000000"> collection = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">X509CertificateCollection</span><span style="color:#000000">(</span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">X509Certificate</span><span style="color:#000000">[] { Certificate });</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">SslStream</span><span style="color:#000000"> ssl_client = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">SslStream</span><span style="color:#000000">(t.GetStream(), </span><span style="color:blue">false</span><span style="color:#000000">, CertificateValidationCallback);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>ssl_client.AuthenticateAsClient(</span><span style="color:#a31515">&quot;localhost&quot;</span><span style="color:#000000">, collection, System.Security.Authentication.</span><span style="color:#2b91af">SslProtocols</span><span style="color:#000000">.Tls, </span><span style="color:blue">false</span><span style="color:#000000">);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>ssl_client.WriteByte(0);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span><span style="">           </span>ssl_client.Close();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>}</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">        </span></span><span style="color:blue">public</span><span style="color:#000000"> </span><span style="color:blue">void</span><span style="color:#000000"> Listen(</span><span style="color:blue">object</span><span style="color:#000000"> x)</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:#2b91af">TcpListener</span><span style="color:#000000"> l = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">TcpListener</span><span style="color:#000000">(9999);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style=""> </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>l.Start();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">            </span></span><span style="color:blue">while</span><span style="color:#000000"> (</span><span style="color:blue">true</span><span style="color:#000000">)</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>{</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">                </span></span><span style="color:#2b91af">TcpClient</span><span style="color:#000000"> c = l.AcceptTcpClient();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"> </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">                </span></span><span style="color:#2b91af">SslStream</span><span style="color:#000000"> ssl_server = </span><span style="color:blue">new</span><span style="color:#000000"> </span><span style="color:#2b91af">SslStream</span><span style="color:#000000">(c.GetStream(), </span><span style="color:blue">false</span><span style="color:#000000">, CertificateValidationCallback);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">                </span>ssl_server.AuthenticateAsServer(Certificate, </span><span style="color:blue"><strong><span style="text-decoration:underline">true</span></strong></span><span style="color:#000000">, System.Security.Authentication.</span><span style="color:#2b91af">SslProtocols</span><span style="color:#000000">.Tls, </span><span style="color:blue">false</span><span style="color:#000000">);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">                </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">       </span><span style="">         </span></span><span style="color:blue">string</span><span style="color:#000000"> ClientCert = (ssl_server.RemoteCertificate == </span><span style="color:blue">null</span><span style="color:#000000">) ? </span><span style="color:#a31515">&quot;null&quot;</span><span style="color:#000000"> : ssl_server.RemoteCertificate.ToString();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">                </span></span><span style="color:#2b91af">MessageBox</span><span style="color:#000000">.Show(ClientCert);</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">                </span></span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style=""><span style="color:#000000">                </span></span><span style="color:blue">int</span><span style="color:#000000"> r = ssl_server.ReadByte();</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">            </span>}</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">        </span>}</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000"><span style="">   </span><span style=""> </span>}</span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-size:10pt;font-family:'Courier New'"><span style="color:#000000">}</span></span></p> <font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p> </p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p> </p>Wed, 18 Nov 2009 16:53:47 Z2009-11-20T17:44:00Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/599a9ede-4a7c-4a24-b0a2-9f464e84dad7http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/599a9ede-4a7c-4a24-b0a2-9f464e84dad7G.Tashttp://social.msdn.microsoft.com/Profile/en-US/?user=G.TasOutOfMemoryException and Bad Performance when sending files over TCP in Windows Mobile 6.1 DeviceHi people,<br/> <br/> This is not a TCP specific error, or not an error exactly, but still, its there bugging me.<br/> Now that i finally have a descent move around objects over TCP, and files too,<br/> i have this problem with performance, but only on my Windows Mobile Device.<br/> <br/> Even when sending a file 640k, it is kinda slow, sometimes sending bigger files<br/> are received, but maybe i will get an OutOfMemoryException. This ofcourse caused by the limited memory in the WM devices.<br/> If no exception will thrown i get the file but during the copy i get slow in the mobile application. <br/> I thought taking the files in another thread and work there while preparing to send and when receiving the bytes,<br/> also i thought always to split them and move parts anytime in another thread. <br/> But again the operation still is very slow! i think it should not get so much time to move e.g. 1mb file.<br/> <br/> Anyone knows how to bypass this? I know i should post this on the CF forum too. But maybe someone could help here too..Fri, 20 Nov 2009 12:30:53 Z2009-11-20T12:30:55Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/c9507135-fb97-4dec-96e2-a76b8304ae24http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/c9507135-fb97-4dec-96e2-a76b8304ae24firesq38http://social.msdn.microsoft.com/Profile/en-US/?user=firesq38http webrequest post (convert from html to vb.net)I have this code that works fine in my htm page.... however I need to convert it to work from a windows form in vb.net. I have tried several examples but nothing happens. Any ideas.<br/> <br/> The form has 1 textbox and 1 button.<br/> <br/> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">&lt;</span> <span style="color:#a31515">form</span> <span style="color:Red">method</span> <span style="color:Blue">=</span> <span style="color:Blue">post</span> <span style="color:Red">action</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;http://www.url.com/cgi-bin/pager.exe&quot;</span> <span style="color:Red">method</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;POST&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">input</span> <span style="color:Red">type</span> <span style="color:Blue">=</span> <span style="color:Blue">hidden</span> <span style="color:Red">name</span> <span style="color:Blue">=</span> <span style="color:Blue">SERVER_IP</span> <span style="color:Red">value</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;000.000.000.000&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">input</span> <span style="color:Red">type</span> <span style="color:Blue">=</span> <span style="color:Blue">hidden</span> <span style="color:Red">name</span> <span style="color:Blue">=</span> <span style="color:Blue">SERVER_PORT</span> <span style="color:Red">value</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;444&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">input</span> <span style="color:Red">type</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;hidden&quot;</span> <span style="color:Red">name</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;NUMBER&quot;</span> <span style="color:Red">value</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;555-1111, 555-2222&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Red">&amp;nbsp;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">font</span> <span style="color:Red">face</span> <span style="color:Blue">=</span> <span style="color:Blue">Arial</span> <span style="color:Red">size</span> <span style="color:Blue">=</span> <span style="color:Blue">-1</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">font</span> <span style="color:Red">face</span> <span style="color:Blue">=</span> <span style="color:Blue">Arial</span> <span style="color:Red">size</span> <span style="color:Blue">=</span> <span style="color:Blue">-1</span> <span style="color:Blue">&gt;</span> Text<span style="color:Red">&amp;nbsp;</span> Message:<span style="color:Blue">&lt;</span> <span style="color:#a31515">br</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">font</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">TEXTAREA</span> <span style="color:Red">ROWS</span> <span style="color:Blue">=</span> <span style="color:Blue">5</span> <span style="color:Red">COLS</span> <span style="color:Blue">=</span> <span style="color:Blue">40</span> <span style="color:Red">NAME</span> <span style="color:Blue">=</span> <span style="color:Blue">MESSAGE</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">TEXTAREA</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">font</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">p</span> <span style="color:Red">align</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;left&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">font</span> <span style="color:Red">face</span> <span style="color:Blue">=</span> <span style="color:Blue">Arial</span> <span style="color:Red">size</span> <span style="color:Blue">=</span> <span style="color:Blue">-1</span> <span style="color:Blue">&gt;</span> <span style="color:Red">&amp;nbsp;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">input</span> <span style="color:Red">type</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;submit&quot;</span> <span style="color:Red">value</span> <span style="color:Blue">=</span> <span style="color:Blue">&quot;SEND PAGE&quot;</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">td</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">tr</span> <span style="color:Blue">&gt;</span> <span style="color:Red">&amp;nbsp;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">p</span> <span style="color:Blue">&gt;</span> <span style="color:Blue">&lt;/</span> <span style="color:#a31515">form</span> <span style="color:Blue">&gt;</span> </pre> </div> SOLUTION FOUND:<br/> <div style="color:Black;background-color:White"> <pre> <span style="color:Green">' Create a request using a URL that can receive a post. </span> <span style="color:Blue">Dim</span> request <span style="color:Blue">As</span> WebRequest = WebRequest.Create(<span style="color:#a31515">&quot;http://www.pager.com/cgi-bin/pager.exe&quot;</span> ) <span style="color:Green">' Set the Method property of the request to POST.</span> request.Method = <span style="color:#a31515">&quot;POST&quot;</span> <span style="color:Green">' Create POST data and convert it to a byte array.</span> <span style="color:Blue">Dim</span> postData <span style="color:Blue">As</span> <span style="color:Blue">String</span> = <span style="color:#a31515">&quot;SERVER_IP=192.168.0.83&amp;SERVER_PORT=444&amp;NUMBER=5554444&amp;MESSAGE=&quot;</span> &amp; TextBox1.Text <span style="color:Blue">Dim</span> byteArray <span style="color:Blue">As</span> <span style="color:Blue">Byte</span> () = Encoding.UTF8.GetBytes(postData) <span style="color:Green">' Set the ContentType property of the WebRequest.</span> request.ContentType = <span style="color:#a31515">&quot;application/x-www-form-urlencoded&quot;</span> <span style="color:Green">' Set the ContentLength property of the WebRequest.</span> request.ContentLength = byteArray.Length <span style="color:Green">' Get the request stream.</span> <span style="color:Blue">Dim</span> dataStream <span style="color:Blue">As</span> Stream = request.GetRequestStream() <span style="color:Green">' Write the data to the request stream.</span> dataStream.Write(byteArray, 0, byteArray.Length) <span style="color:Green">' Close the Stream object.</span> dataStream.Close() <span style="color:Green">' Get the response.</span> <span style="color:Blue">Dim</span> response <span style="color:Blue">As</span> WebResponse = request.GetResponse() <span style="color:Green">' Display the status.</span> Console.WriteLine(<span style="color:Blue">CType</span> (response, HttpWebResponse).StatusDescription) <span style="color:Green">' Get the stream containing content returned by the server.</span> dataStream = response.GetResponseStream() <span style="color:Green">' Open the stream using a StreamReader for easy access.</span> <span style="color:Blue">Dim</span> reader <span style="color:Blue">As</span> <span style="color:Blue">New</span> StreamReader(dataStream) <span style="color:Green">' Read the content.</span> <span style="color:Blue">Dim</span> responseFromServer <span style="color:Blue">As</span> <span style="color:Blue">String</span> = reader.ReadToEnd() <span style="color:Green">' Display the content.</span> Console.WriteLine(responseFromServer) <span style="color:Green">' Clean up the streams.</span> reader.Close() dataStream.Close() response.Close() <span style="color:Blue">End</span> <span style="color:Blue">Sub</span> </pre> </div> <br/>Thu, 19 Nov 2009 18:34:40 Z2009-11-19T21:05:23Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/7b50fecd-f0cb-467e-b3d4-7942958096c4http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/7b50fecd-f0cb-467e-b3d4-7942958096c4s.a.nabeelhttp://social.msdn.microsoft.com/Profile/en-US/?user=s.a.nabeelPager Message AT CommandPlease somebody help me to write code to send pager messages using AT Modem Commands. My client has his modem connected to the computer and I want to write a code that communicate this modem using com port and send pager messages using the modem. I searched the entire web and couldn’t find a sample code to send pager message using AT Command .What I want to do is to send a pager message to a pager using a modem connected to the pc.To dial a pager number I should follow the command &quot;ATD \r\n&quot; . What I want to do is first connect to my pager providers number , then call the actual pager number of the callee , then I should send the message to be received by the callee .I just know the above mentioned command only. Please provide an AT Command for this procedure. Please somebody help me on this. Thanks :)<br/>Thu, 19 Nov 2009 12:42:24 Z2009-11-19T12:42:25Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/c1240154-7f89-43b8-b17a-5897f7cbd292http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/c1240154-7f89-43b8-b17a-5897f7cbd292actief74http://social.msdn.microsoft.com/Profile/en-US/?user=actief74System.Net.Mail.SmtpException: Error in processing. The server response was: 4.7.0 Timeout waiting for client inputHello,<br/><br/>We have this error, does somebody know what the problem could be:<br/><br/>System.Net.Mail.SmtpException: Error in processing. The server response was: 4.7.0 Timeout waiting for client input<br/>at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)<br/>at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)<br/>at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException&amp; exception)<br/>at System.Net.Mail.SmtpClient.Send(MailMessage message)<br/>at BE.home.test.EMail.SendEmail(MailMessage msg)<br/>at BE.home.test.EMail.SendHTMLEmail(String[] recipients, String sender, String subject, String bodyhtml)<br/>at BE.home.test.EMail.SendHTMLEmail(String recipient, String sender, String subject, String bodyhtml)<br/><br/>BE.home.test is fake because of privacy, the rest is orginaly from the error.<br/><br/>thanks for your help in advance<br/>regards MarcelThu, 19 Nov 2009 10:15:18 Z2009-11-23T07:04:52Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/40fe397c-b1da-428e-a355-ee5a6b0b4d2chttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/40fe397c-b1da-428e-a355-ee5a6b0b4d2cvictor.pohttp://social.msdn.microsoft.com/Profile/en-US/?user=victor.poSocketAsyncEventArgs.SetBuffer() bug ?I found the following problem when using SocketAsyncEventArgs.SetBuffer() method along with SendAsync and ReceiveAsync:<br/> (not sure where is better place to report/discuss that)<br/> <br/> Symptoms: under high load on multiprocessor machine, SetBuffer() will not update internal fields correctly, and that will cause incorrect size of data being sent down the wire among other possible scenarios. Placing easy check in SendAsync completion method traps the error for inspection.<br/> case SocketAsyncOperation.Send: if( ea.Count != ea.BytesTransferred )  OnError( ... );<br/> <br/> Sample error data: for instance, after sending 166 bytes with SendAsync, ea.Count will be == 166, but ea.BytesTransferred will contain value 8192. That value was set by SetBuffer called before ReadAsync call was executed on same socket, but on another thread, our SetBuffer/SendAsync methods were called from ReadAsync callback(not in parallel). I have a screenshot(not sure how to attach this image here) that shows internal field m_WSABuffer.Length == 8192 at this point, while Count = 166 and LastOperation == Send (correct value for Length should also be 166). <br/> <br/> Possible explanation: error happens due to the code in the private method CheckPinSingleBuffer(as could be seen in Reflector tool), that compares 2 object fields to avoid setting m_WSABuffer struct values. So, when Count value is first set by SetBuffer() on processor 1, then changed to another value in completion callback on processor 2(along with m_WSABuffer.Length) and then completion callback called again on processor 1, code that compares field objects sees equal(from processor cache) and does not update m_WSABuffer.Length to correct value. That how calling SetBuffer( .., offset, 166 ) could actually send 8192 bytes. Important note: while this calls happens on different threads/cores, logically they are strictly sequential. <br/> <br/> Fortunately this error has a small chance to happen outside &quot;stress test scenario&quot;, as it requires that 1st and 3rd SetBuffer() calls in explanation pass same Count value(that easily happens with repeatable size requests). Still, it was found during load testing sockets based http client, and may show up in actual deployed apps.<br/> <br/> <img alt=""> <img alt=""> Workaround found(sigh): placing lock/unlock calls before SetBuffer and after SendAsync/ReceiveAsync prevents error (or make it happen much less frequent) probably by giving cores more time to get memory/caches in sync. <br/> <br/> Possible fix: Microsoft can update SocketAsyncEventArgs private methods to use VolatileRead or mark as volatile fields m_PinnedSingleBufferCount and m_PinnedSingleBufferOffset<span style="text-decoration:underline"><br/> <br/> </span> P.S. Simple client and server applications that demonstrate problem are available.<span style="text-decoration:underline"><br/> </span>Thu, 19 Nov 2009 03:56:23 Z2009-11-19T03:56:24Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/44e503de-90b5-4a8e-adaf-322133899109http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/44e503de-90b5-4a8e-adaf-322133899109hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzlocation of Send and Receive methods for asynchronous client sockets.<p>I put the Send()       in  ConnectCallback().<br/>I put the Receive()  in  SendCallBack after the SendDone.Set();<br/>Does this make sense?  I initially put Receive()  right after Send() in ConnectCallBack();  Thank you. <br/></p> <pre lang="x-c#"> public static void ConnectCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; client.EndConnect(ar); connectDone.Set(); Send(client); // Receive(client); } private static void Send(Socket client) { client.BeginSend(toSocket, 0, toSocket.Length, SocketFlags.None, new AsyncCallback(SendCallback), client); } private static void SendCallback(IAsyncResult ar) { Socket client = (Socket)ar.AsyncState; int bytesSent = client.EndSend(ar); sendDone.Set(); Receive(client); }</pre>Tue, 17 Nov 2009 21:35:07 Z2009-11-19T02:43:12Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/927d20bb-3414-436d-bc97-f980b918569dhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/927d20bb-3414-436d-bc97-f980b918569dcomamerohttp://social.msdn.microsoft.com/Profile/en-US/?user=comameroTheoretical question about net communication and others.Hello everybody!<br/> <br/> I have some questions.<br/> <br/> I have a little software company (big word;)) and I need to write some &quot;<span class="short_text"><span style="background-color:#ebeff9" title="licencja programu">licenses</span> </span> manager&quot;, and I don't know how it write professionalists<br/> <br/> In my vision I have dll which I add to my application which I sold and that dll send info to my server, server do something with that info and send response to app. If response seys that is all right app starts if not app shout down.<br/> <br/> How to <span class="short_text"><span style="background-color:#ffffff" title="komunikować">communicate</span> </span> app's and server (it must be safe). Is SSL good enough?<br/> Do you know better scenario?<br/> How it works in big <span class="short_text"><span style="background-color:#ebeff9" title="dwie firmy">companies?</span> </span> <br/>Wed, 18 Nov 2009 21:55:01 Z2009-11-18T21:55:02Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0bc07667-0f17-446e-a36f-d9203cc8425chttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/0bc07667-0f17-446e-a36f-d9203cc8425cjschellhttp://social.msdn.microsoft.com/Profile/en-US/?user=jschellHttpListener backlogHttpListener must have a backlog.  This would be similar to Socket.Listen(int backlog).<br/><br/>It might be implicit via a registry entry, settable in code or even a hard value.<br/><br/>So which is it?  And if the first and/or second then where are they?Wed, 18 Nov 2009 19:43:48 Z2009-11-18T19:43:48Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/bc1a6d8b-f606-4689-8df9-3bcf1cd4af45http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/bc1a6d8b-f606-4689-8df9-3bcf1cd4af45Mark Wroblewskihttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20Wroblewski.NET Double Authentication IssueI am currently working on a project that is using .NET WebRequests to contact authenticated RestFul services.  The code that we are using is very simple, almost right out of an example, yet the problem we are encountering seems to require a fix that we cannot implement on our customers servers.<br/><br/>The code we are using is:<br/><br/> <pre lang="x-c#"> //Open a WebRequest.... This is a public IP address so you build this and test it out. WebRequest request = HttpWebRequest.Create(&quot;http://X.X.X.X/api/post/&quot;); //Send encode the username and password byte[] authBytes = Encoding.UTF8.GetBytes((&quot;username:password&quot;).ToCharArray()); //Basic authentication--POST request. request.Headers[&quot;AUTHORIZATION&quot;] = &quot;Basic &quot; + Convert.ToBase64String(authBytes); request.ContentType = &quot;application/x-www-form-urlencoded&quot;; request.Method = &quot;POST&quot;; //The daa for the service. Harded coded Accounts parameter 1 and currently &quot;Test post&quot; for a message String data = String.Format(&quot;message={0};accounts=1&quot;, HttpUtility.UrlEncode(&quot;Test post&quot;)); byte[] bytes = Encoding.UTF8.GetBytes(data); request.ContentLength = bytes.Length; System.Net.ServicePointManager.Expect100Continue = false; using (Stream requestStream = request.GetRequestStream()){ requestStream.Write(bytes, 0, bytes.Length); using (WebResponse response = (WebResponse)request.GetResponse()){ using (StreamReader reader = new StreamReader(response.GetResponseStream())){ //If the POST request is successful then we will get a JSON object back containing our message. Console.WriteLine(reader.ReadToEnd()); } } } Console.WriteLine(&quot;&quot;); Console.WriteLine(&quot;Press any key to continue...&quot;); Console.ReadLine();</pre> When the above code is executed without the fix in place the request returns a 500 Internal Server Error.  <br/><br/>After some investigation we determined that .NET is sending two WebRequests each and every time.  The first request does not contain the username and password which the services are expecting--thus the error.<br/><br/>We found a solution to disable the loopback check on the LSA for the entire OS by adding the following key to the system registry:<br/><br/> <p class=MsoNormal style="line-height:normal;margin:0in 0in 0pt"><span style="font-family:'Tahoma','sans-serif';font-size:10pt">hkey_local_machine&gt;system&gt;currentcontrolset&gt;control&gt;lsa</span><span style="font-family:'Times New Roman','serif';font-size:12pt"></span></p> <p class=MsoNormal style="line-height:normal;margin:0in 0in 0pt"><span style="font-family:'Times New Roman','serif';font-size:12pt"> </span></p> <p class=MsoNormal style="line-height:normal;margin:0in 0in 0pt"><span style="font-family:'Tahoma','sans-serif';font-size:10pt">add a new DWORD &quot;DisableLoopbackCheck&quot; and set it to 1</span><span style="font-family:'Times New Roman','serif';font-size:12pt"></span></p> <p class=MsoNormal style="line-height:normal;margin:0in 0in 0pt"><br/><br/>What do I need to do within my C# program to either force a username and password to the first request or disable the double request functionality.  The goal would be to get the program to function without altering the performance of the LSA or by adding any registry key.  <br/><br/>Simply turning off a portion of functionality across an entire server farm is going to be unacceptable.<br/><br/>Thank you,<br/><br/>Mark<br/></p> <p class=MsoNormal style="line-height:normal;margin:0in 0in 0pt"><span style="font-family:'Times New Roman','serif';font-size:12pt"><br/></span></p>Tue, 17 Nov 2009 16:38:35 Z2009-11-18T18:06:16Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/64bebd50-636b-4374-a5d1-112666bcfd41http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/64bebd50-636b-4374-a5d1-112666bcfd41ybastianhttp://social.msdn.microsoft.com/Profile/en-US/?user=ybastianCannot set the MAIL FROM SMTP property when using System.Net.Mail.SmtpClient classHi,<br/> <br/> I am using the System.Net.Mail.SmtpClient for sending some Emails that are automatically generated by my server.<br/> <br/> I would like to set the MAIL FROM of the envelope in the SMTP protocol, without this information appearing anywhere else in the SMTP discussion. I can't find a way to do this.<br/> <br/> I have tried using the SmtpDeliveryMethod.Network as described in the following post:<br/> http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/a26c273a-18eb-4143-8631-233088977b21/<br/> <br/> It indeed results in having the MailMessage.Sender property used as the MAIL FROM. However the MailMessage.Sender property also appears in the EMail data in the Sender property, which is displayed to the recipients of the Email (displayed as follows in Outlook 2003):<br/> &lt;MailMessage.Sender&gt; on behalf of &lt;MailMessage.From&gt;<br/> <br/> My motivation is that I want to be able to provide a valid, existing Email address in the MAIL FROM of the SMTP discussion. This is because some EMail servers will not transfer an EMail if the MAIL FROM is not valid.<br/> However I do not want the MAIL FROM Email address to be available to the recipients of the Email. This is because in some cases, my EMail server generates automatic EMails to which the user should not answer.<br/> <br/> Thanks in advance for your help,<br/> <br/> Yves.Wed, 18 Nov 2009 10:27:19 Z2009-11-18T11:45:13Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/176963d7-3f99-4c9c-9969-1d265cb929c6http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/176963d7-3f99-4c9c-9969-1d265cb929c6hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzDo I have to explicitly make sure [FIN,ACK] happens when talking to a device?<p>The C++ app I am rewriting is communicating correctly with the target device.<br/>I can see using WireShark that my client is sending a [FIN,ACK] to the server. And the server sends it back.<br/>My app is not doing this.<br/>Do I have to explicitly do this myself in my sockets code?<br/><strong>[EDIT - I THINK FEROZE ALREADY GAVE ME THE ANSWER TO THIS IN A PREVIOUS POST-ShutDown/Close as follows]<br/>Object syncObj = <span style="color:blue">new</span> Object();<br/><br/><span style="color:blue">void</span> TimedOut(<span style="color:blue">object</span> state)<br/>{<br/>      <span style="color:blue">lock</span>(syncObj)<br/>      {<br/>              <span style="color:green">// timed out. close and shutdown socket</span><br/>              socket.Shutdown(SocketShutdown.Both);<br/>              socket.Close();<br/>      }<br/>}<br/>[END EDIT]</strong><br/>I am adhering closely to the following set of patterns and mechanisms in <a href="http://msdn.microsoft.com/en-us/library/bbx2eya8.aspx">http://msdn.microsoft.com/en-us/library/bbx2eya8.aspx</a>  (<strong>Using an Asynchronous Client Socket</strong> ) namely Connect, Send, Recieve and their Callback functions. <br/><br/>My app is correctly sending and receiving  SYN, ACK, PSH  messages but when it comes to FIN,ACK , not so.  I think I have to properly shutdown,close the connection but I'm not quite sure where/how to do that. <br/><br/>When I try to close the socket right after the last receive, an error is thrown (sorry I don't have the error message but I'll find out when I get back to the lab)<br/><br/>Thank you,<br/>Greg</p>Tue, 17 Nov 2009 22:34:15 Z2009-11-18T18:11:41Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/1e9762d0-4e1d-4fa4-bfe5-ecae036226f1http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/1e9762d0-4e1d-4fa4-bfe5-ecae036226f1hazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzReceiveCallback for asynch socket client not getting called.This callback is designed to be called from within itself in order to retrieve any more incoming bytes from a socket server.<br/>But the callback never gets called again.  What reason could there be that the client.BeginReceive(xxx) never calls its container method?   The code execution path makes it to this statement (bytesRead = 81).  Thank you for any ideas.<br/><br/> <pre lang="x-c#"> private static void ReceiveCallback(IAsyncResult ar) { StateObject state = (StateObject) ar.AsyncState; Socket client = state.workSocket; int bytesRead = client.EndReceive(ar); if (bytesRead &gt; 0) { // There might be more data, so store the data received so far. sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead)); // Get the rest of the data. client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); } else { // All the data has arrived; put it in response. if (state.sb.Length &gt; 1) { response = state.sb.ToString(); } // Signal that all bytes have been received. receiveDone.Set(); } } }</pre> <br/>Tue, 17 Nov 2009 21:22:05 Z2009-11-17T21:46:55Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2d7abae6-bc86-434b-94aa-ced03630177ehttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2d7abae6-bc86-434b-94aa-ced03630177ehazzhttp://social.msdn.microsoft.com/Profile/en-US/?user=hazzneed to wait x amount of seconds for a response from server using sockets asynchronously<p>I'm still trying to understand my asynchronous sockets scenario and sockets themselves.<br/><br/>I want to send an initial stream of bytes to a server and allow for a certain timeperiod to see if a valid response packet is received.<br/>I'll be checking for a certain header frame to verify that this is the beginning of the packet stream I'm expecting.<br/>I'm using <br/>    1. BeginConnect() to connect to my listening host.<br/>    2. BeginSend() to send an array of bytes my host will understand.<br/>    3. PacketReceivedFromHost(IAsynchResult result) as the callback function.<br/><br/>Three questions.<br/>    1.  Where do I put the timer value (the period to wait for sufficient response time from host) ?<br/>    2   Where do I put the code that will evaluate the received packet stream?  In PacketReceivedFromHost()?<br/>    3.  Do I need to add BeginAccept() or is PacketReceivedFromHost() sufficient which is the callback instantiated within the BeginSend method?<br/><br/>Some sample code follows;  Thank you for your patience as I try to clarify all this.<br/></p> <pre lang="x-c#"> public class StateObject { public Socket workSocket = null; public const int BUFFER_SIZE = 2400; public byte[] buffer = new byte[BUFFER_SIZE]; public StringBuilder sb = new StringBuilder(); } public partial class Form1 : Form { private static byte[] toSocket; private static byte[] fromRemoteServer = new byte[2400]; public Form1() { InitializeComponent(); toSocket = new byte[7]; toSocket[0] = 2; //msgID toSocket[1] = 0; //status toSocket[2] = 0; //data lehgth toSocket[3] = 0; toSocket[4] = 0; //seq # toSocket[5] = 1; } private void button1_Click(object sender, EventArgs e) { BeginConnect(&quot;10.0.110.35&quot;, 50000); } //Establishing the Connection // Asynchronous connect using the host name, resolved via IPAddress public static void BeginConnect(string host, int port) { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); allDone.Reset(); Console.WriteLine(&quot;Establishing Connection to {0}&quot;, host); s.BeginConnect(host, port, new AsyncCallback(Connected), s); // wait here until the connect finishes. // The callback sets allDone. allDone.WaitOne(); Console.WriteLine(&quot;Connection established&quot;); } // handles the completion of the prior asynchronous connect call. // the socket is passed via the objectState parameter of BeginConnect(). public static void Connected(IAsyncResult ar) { allDone.Set(); Socket s = (Socket)ar.AsyncState; try { s.EndConnect(ar); } catch (SocketException) { Console.WriteLine(&quot;Unable to connect to host&quot;); } s.BeginSend(toSocket, 0, toSocket.Length, 0, new AsyncCallback(SendData), s); s.BeginReceive(fromRemoteServer, 0, fromRemoteServer.Length, SocketFlags.None, new AsyncCallback(ReceivedData), s); } private static void SendData(IAsyncResult iar) { Socket server = (Socket)iar.AsyncState; int sent = server.EndSend(iar); } // The following method is called when each asynchronous operation completes. private static void ReceivedData(IAsyncResult iar) { Socket remote = (Socket)iar.AsyncState; int recv = remote.EndReceive(iar); string receivedData = Encoding.ASCII.GetString(fromRemoteServer, 0, recv); Console.WriteLine(receivedData); } public static ManualResetEvent allDone = new ManualResetEvent(false); }</pre>Mon, 16 Nov 2009 16:39:56 Z2009-11-17T20:59:49Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e9829e44-53f5-471b-8808-d08a13e63bf8http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/e9829e44-53f5-471b-8808-d08a13e63bf8scttytrmnhttp://social.msdn.microsoft.com/Profile/en-US/?user=scttytrmnWebClient:UploadFile fails with bigger fileshi <br/> <br/> i got a problem with uploading files: <br/> i'm using the upload inside a wordaddin. the addin sends the file to a php file which just saves it. works well with smaller files, but when it comes to larger files like &gt;8mbyte or something, the uploadprocess stops:<br/> http://img149.imageshack.us/img149/8881/wufehler.jpg<br/> the error can be translated as &quot;the request has been canceled: the request hast been canceled...&quot;<br/> <br/> i set all variables relating limits in the php.ini to high values like<br/> <br/> <table border=0 cellpadding=3 width=600> <tbody> <tr> <td class=e>max_execution_time</td> <td class=v>1234</td> <td class=v>1234</td> </tr> </tbody> </table> <table border=0 cellpadding=3 width=600> <tbody> <tr> <td class=e>max_input_time</td> <td class=v>600</td> <td class=v>600</td> </tr> <tr> <td class=e>memory_limit</td> <td class=v>512M</td> <td class=v>512M</td> </tr> </tbody> </table> <table border=0 cellpadding=3 width=600> <tbody> <tr> <td class=e>post_max_size</td> <td class=v>800M</td> <td class=v>800M</td> </tr> </tbody> </table> <table border=0 cellpadding=3 width=600> <tbody> <tr> <td class=e>upload_max_filesize</td> <td class=v>128M</td> <td class=v>128M</td> </tr> </tbody> </table> <br/> and a web develop board told me i should reconsider the option that my .net addin fails...<br/> <br/>Wed, 26 Aug 2009 07:40:15 Z2009-11-17T19:21:49Zhttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/072ff21c-6087-4ccf-916b-ef59c7755bfahttp://social.msdn.microsoft.com/Forums/en-US/ncl/thread/072ff21c-6087-4ccf-916b-ef59c7755bfaG.Tashttp://social.msdn.microsoft.com/Profile/en-US/?user=G.TasNito Message Framing strange problems...This is most goes for Stephen but anyone who would post is welcome.<br/> I know i've been annoying the last days about TCP Sockets, and now i am so<br/> most fully understood the concept.<br/> <br/> While using this codes <a href="http://nitoprograms.blogspot.com/2009/04/sample-code-length-prefix-message.html">http://nitoprograms.blogspot.com/2009/04/sample-code-length-prefix-message.html</a> <br/> And seems to work better and as many times i push the button data comes lightning, but...<br/> In some circumstances while im transferring from 2 specific objects an array of instances i lose track of the data<br/> and one side drops. Something goes wrong i guess in the ReadCompleted() method. Same with files, a little bigger file would cause<br/> losing track of the Socket. The object array is not so big...talking about 5-6 instances. Will check this again though for any incovinience.<br/> <br/> Only things i changed in the code is that i pass the State object of mine in the DataReceived() and ReadCompleted() methods while throwing it out again<br/> in the Action&lt;&gt; event. More i removed the code for keepalive zero-length data, i will handle this differentely if i want too.<br/> <br/> Another thing here is the OutOfMemoryException is been thrown while i request data in my Compact Framework platform while the implementation<br/> is exactly the same as the Desktop Framework and works in this case?<br/> <br/> Exception thrown here:<br/>                     // Create the data buffer and start reading into it<br/>                     this.dataBuffer = new byte[length]; &lt;--- OutOfMemoryException because of big length variable!<br/>                     this.bytesReceived = 0;<br/> <br/> I use Async Methods on Send/Receive Part.<br/> <br/> Would be great to finish this :) Please some support from Stephen. Thank you in advance.<br/>Tue, 17 Nov 2009 12:40:03 Z2009-11-17T18:13:35Z