[System*] Add category for tests that use API that require BSD sockets.
[mono.git] / mcs / class / System / Test / System.Net / FtpWebRequestTest.cs
1 //
2 // FtpWebRequestTest.cs - NUnit Test Cases for System.Net.FtpWebRequest
3 //
4 // Authors:
5 //      Carlos Alberto Cortez <calberto.cortez@gmail.com>
6 //      Gonzalo Paniagua Javier <gonzalo@novell.com>
7 //
8 // Copyright (c) 2006,2007,2008 Novell, Inc. (http://www.novell.com)
9 //
10 using NUnit.Framework;
11 using System;
12 using System.Collections.Generic;
13 using System.IO;
14 using System.Net;
15 using System.Net.Sockets;
16 using System.Text;
17 using System.Threading;
18
19 namespace MonoTests.System.Net 
20 {
21         [TestFixture]
22         [Category ("RequiresBSDSockets")]
23         public class FtpWebRequestTest
24         {
25                 FtpWebRequest defaultRequest;
26                 
27                 private string _tempDirectory;
28                 private string _tempFile;
29
30                 [SetUp]
31                 public void SetUp ()
32                 {
33                         _tempDirectory = Path.Combine (Path.GetTempPath (), "MonoTests.System.Net.FileWebRequestTest");
34                         _tempFile = Path.Combine (_tempDirectory, "FtpWebRequestTest.tmp");
35                         if (!Directory.Exists (_tempDirectory)) {
36                                 Directory.CreateDirectory (_tempDirectory);
37                         } else {
38                                 // ensure no files are left over from previous runs
39                                 string [] files = Directory.GetFiles (_tempDirectory, "*");
40                                 foreach (string file in files)
41                                         File.Delete (file);
42                         }
43                 }
44
45                 [TearDown]
46                 public void TearDown ()
47                 {
48                         if (Directory.Exists (_tempDirectory))
49                                 Directory.Delete (_tempDirectory, true);
50                 }
51
52                 [TestFixtureSetUp]
53                 public void Init ()
54                 {
55                         defaultRequest = (FtpWebRequest) WebRequest.Create ("ftp://www.contoso.com");
56                 }
57                 
58                 [Test]
59                 public void ContentLength ()
60                 {
61                         try {
62                                 long l = defaultRequest.ContentLength;
63                         } catch (NotSupportedException) {
64                                 Assert.Fail ("#1"); // Not overriden
65                         }
66
67                         try {
68                                 defaultRequest.ContentLength = 2;
69                         } catch (NotSupportedException) {
70                                 Assert.Fail ("#2"); // Not overriden
71                         }
72                 }
73
74                 [Test]
75                 public void ContentType ()
76                 {
77                         try {
78                                 string t = defaultRequest.ContentType;
79                                 Assert.Fail ("#1");
80                         } catch (NotSupportedException) {
81                         }
82
83                         try {
84                                 defaultRequest.ContentType = String.Empty;
85                                 Assert.Fail ("#2");
86                         } catch (NotSupportedException) {
87                         }
88                 }
89
90                 [Test]
91                 public void ContentOffset ()
92                 {
93                         try {
94                                 defaultRequest.ContentOffset = -2;
95                                 Assert.Fail ("#1");
96                         } catch (ArgumentOutOfRangeException) {
97                         }
98                 }
99
100                 [Test]
101                 public void Credentials ()
102                 {
103                         try {
104                                 defaultRequest.Credentials = null;
105                                 Assert.Fail ("#1");
106                         } catch (ArgumentNullException) {
107                         }
108
109                 }
110
111                 [Test]
112                 public void Method ()
113                 {
114                         try {
115                                 defaultRequest.Method = null;
116                                 Assert.Fail ("#1");
117                         } catch (ArgumentNullException) {
118                         }
119
120                         try {
121                                 defaultRequest.Method = String.Empty;
122                                 Assert.Fail ("#2");
123                         } catch (ArgumentException) {
124                         }
125
126                         try {
127                                 defaultRequest.Method = "WrongValue";
128                                 Assert.Fail ("#3");
129                         } catch (ArgumentException) {
130                         }
131                 }
132
133                 [Test]
134                 public void PreAuthenticate ()
135                 {
136                         try {
137                                 bool p = defaultRequest.PreAuthenticate;
138                                 Assert.Fail ("#1");
139                         } catch (NotSupportedException) {
140                         }
141
142                         try {
143                                 defaultRequest.PreAuthenticate = true;
144                         } catch (NotSupportedException) {
145                         }
146                 }
147
148                 [Test]
149                 public void ReadWriteTimeout ()
150                 {
151                         try {
152                                 defaultRequest.ReadWriteTimeout = -2;
153                                 Assert.Fail ("#2");
154                         } catch (ArgumentOutOfRangeException) {
155                         }
156                 }
157
158                 [Test]
159                 public void Timeout ()
160                 {
161                         try {
162                                 defaultRequest.Timeout = -2;
163                                 Assert.Fail ("#2");
164                         } catch (ArgumentOutOfRangeException) {
165                         }
166                 }
167                 
168                 [Test]
169                 public void DefaultValues ()
170                 {
171                         FtpWebRequest request = (FtpWebRequest) WebRequest.Create ("ftp://www.contoso.com");
172                         
173                         Assert.AreEqual (0, request.ContentOffset, "ContentOffset");
174                         Assert.AreEqual (false, request.EnableSsl, "EnableSsl");
175                         // FIXME: Disabled this one by now. KeepAlive is not well supported.
176                         // Assert.AreEqual (true, request.KeepAlive, "KeepAlive");
177                         Assert.AreEqual (WebRequestMethods.Ftp.DownloadFile, request.Method, "#1");
178                         Assert.AreEqual (300000, request.ReadWriteTimeout, "ReadWriteTimeout");
179                         Assert.IsNull (request.RenameTo, "RenameTo");
180                         Assert.AreEqual (true, request.UseBinary, "UseBinary");
181                         Assert.AreEqual (100000, request.Timeout, "Timeout");
182                         Assert.AreEqual (true, request.UsePassive, "UsePassive");
183                 }
184
185                 [Test]
186                 public void RenameTo ()
187                 {
188                         try {
189                                 defaultRequest.RenameTo = null;
190                                 Assert.Fail ("#1");
191                         } catch (ArgumentException) {
192                         }
193
194                         try {
195                                 defaultRequest.RenameTo = String.Empty;
196                                 Assert.Fail ("#2");
197                         } catch (ArgumentException) {
198                         }
199                 }
200
201                 [Test]
202                 public void UploadFile1 ()
203                 {
204                         ServerPut sp = new ServerPut ();
205                         sp.Start ();
206                         string uri = String.Format ("ftp://{0}:{1}/uploads/file.txt", sp.IPAddress, sp.Port);
207                         try {
208                                 FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri);
209                                 ftp.KeepAlive = false;
210                                 ftp.Timeout = 5000;
211                                 ftp.Method = WebRequestMethods.Ftp.UploadFile;
212                                 ftp.ContentLength = 10;
213                                 ftp.UseBinary = true;
214                                 Stream stream = ftp.GetRequestStream ();
215                                 for (int i = 0; i < 10; i++)
216                                         stream.WriteByte ((byte)i);
217                                 stream.Close ();
218                                 FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ();
219                                 Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "UP#01");
220                                 Assert.AreEqual (10, sp.result.Count, "UP#02");
221                                 response.Close ();
222                         } catch (Exception) {
223                                 if (!String.IsNullOrEmpty (sp.Where))
224                                         throw new Exception (sp.Where);
225                                 throw;
226                         } finally {
227                                 sp.Stop ();
228                         }
229                 }
230
231                 [Test]
232                 public void UploadFile_WebClient ()
233                 {
234                         ServerPut sp = new ServerPut ();
235                         File.WriteAllText (_tempFile, "0123456789");
236                         sp.Start ();
237
238                         using (WebClient m_WebClient = new WebClient())
239                         {
240                                 string uri = String.Format ("ftp://{0}:{1}/uploads/file.txt", sp.IPAddress, sp.Port);
241                                 
242                                 m_WebClient.UploadFile(uri, _tempFile);
243                         }
244                         Assert.AreEqual (10, sp.result.Count, "WebClient/Ftp#01");
245             
246                         sp.Stop ();
247                 }
248
249                 [Test]
250                 public void DownloadFile1 ()
251                 {
252                         DownloadFile (new ServerDownload ());
253                 }
254
255                 void DownloadFile (ServerDownload sp)
256                 {
257                         sp.Start ();
258                         string uri = String.Format ("ftp://{0}:{1}/file.txt", sp.IPAddress, sp.Port);
259                         try {
260                                 FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri);
261                                 ftp.KeepAlive = false;
262                                 ftp.Timeout = 5000;
263                                 ftp.Method = WebRequestMethods.Ftp.DownloadFile;
264                                 ftp.UseBinary = true;
265                                 FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ();
266                                 Assert.IsTrue ((int) response.StatusCode >= 100 && (int) response.StatusCode < 200, "DL#01");
267                                 using (Stream st = response.GetResponseStream ()) {
268                                 }
269                                 // This should be "220 Bye" or similar (no KeepAlive)
270                                 Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DL#02");
271                                 response.Close ();
272                         } catch (Exception) {
273                                 if (!String.IsNullOrEmpty (sp.Where))
274                                         throw new Exception (sp.Where);
275                                 throw;
276                         } finally {
277                                 sp.Stop ();
278                         }
279                 }
280
281                 [Test]
282                 public void DownloadFile2 ()
283                 {
284                         // Some embedded FTP servers in Industrial Automation Hardware report
285                         // the PWD using backslashes, but allow forward slashes for CWD.
286                         DownloadFile (new ServerDownload (@"\Users\someuser", "/Users/someuser/"));
287                 }
288
289                 [Test]
290                 public void DeleteFile1 ()
291                 {
292                         ServerDeleteFile sp = new ServerDeleteFile ();
293                         sp.Start ();
294                         string uri = String.Format ("ftp://{0}:{1}/file.txt", sp.IPAddress, sp.Port);
295                         try {
296                                 FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri);
297                                 Console.WriteLine (ftp.RequestUri);
298                                 ftp.KeepAlive = false;
299                                 ftp.Timeout = 5000;
300                                 ftp.Method = WebRequestMethods.Ftp.DeleteFile;
301                                 ftp.UseBinary = true;
302                                 FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ();
303                                 Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DF#01");
304                                 response.Close ();
305                         } catch (Exception e) {
306                                 Console.WriteLine (e);
307                                 if (!String.IsNullOrEmpty (sp.Where))
308                                         throw new Exception (sp.Where);
309                                 throw;
310                         } finally {
311                                 sp.Stop ();
312                         }
313                 }
314
315                 [Test]
316                 public void ListDirectory1 ()
317                 {
318                         ServerListDirectory sp = new ServerListDirectory ();
319                         sp.Start ();
320                         string uri = String.Format ("ftp://{0}:{1}/somedir/", sp.IPAddress, sp.Port);
321                         try {
322                                 FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri);
323                                 Console.WriteLine (ftp.RequestUri);
324                                 ftp.KeepAlive = false;
325                                 ftp.Timeout = 5000;
326                                 ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
327                                 ftp.UseBinary = true;
328                                 using (FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ()) {
329                                         StreamReader reader = new StreamReader (response.GetResponseStream ());
330                                         string result = reader.ReadToEnd ();
331                                         Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DF#01");
332                                 }
333                         } catch (Exception e) {
334                                 Console.WriteLine (e);
335                                 if (!String.IsNullOrEmpty (sp.Where))
336                                         throw new Exception (sp.Where);
337                                 throw;
338                         } finally {
339                                 sp.Stop ();
340                         }
341                 }
342
343                 class ServerListDirectory : FtpServer {
344                         protected override void Run ()
345                         {
346                                 Socket client = control.Accept ();
347                                 NetworkStream ns = new NetworkStream (client, false);
348                                 StreamWriter writer = new StreamWriter (ns, Encoding.ASCII);
349                                 StreamReader reader = new StreamReader (ns, Encoding.UTF8);
350                                 if (!DoAnonymousLogin (writer, reader)) {
351                                         client.Close ();
352                                         return;
353                                 }
354
355                                 if (!DoInitialDialog (writer, reader, "/home/someuser", "/home/someuser/somedir/")) {
356                                         client.Close ();
357                                         return;
358                                 }
359
360                                 string str = reader.ReadLine ();
361                                 if (str != "PASV") {
362                                         Where = "PASV";
363                                         client.Close ();
364                                         return;
365                                 }
366
367                                 IPEndPoint end_data = (IPEndPoint) data.LocalEndPoint;
368                                 byte [] addr_bytes = end_data.Address.GetAddressBytes ();
369                                 byte [] port = new byte [2];
370                                 port[0] = (byte) ((end_data.Port >> 8) & 255);
371                                 port[1] = (byte) (end_data.Port & 255);
372                                 StringBuilder sb = new StringBuilder ("227 Passive (");
373                                 foreach (byte b in addr_bytes) {
374                                         sb.AppendFormat ("{0},", b);    
375                                 }
376                                 sb.AppendFormat ("{0},", port [0]);     
377                                 sb.AppendFormat ("{0})", port [1]);     
378                                 writer.WriteLine (sb.ToString ());
379                                 writer.Flush ();
380
381                                 str = reader.ReadLine ();
382                                 if (str != "LIST") {
383                                         Where = "LIST - '" + str + "'";
384                                         client.Close ();
385                                         return;
386                                 }
387                                 writer.WriteLine ("150 Here comes the directory listing");
388                                 writer.Flush ();
389
390                                 Socket data_cnc = data.Accept ();
391                                 byte [] dontcare = Encoding.ASCII.GetBytes ("drwxr-xr-x    2 ftp      ftp          4096 Oct 27 20:17 tests");
392                                 data_cnc.Send (dontcare, 1, SocketFlags.None);
393                                 data_cnc.Close ();
394                                 writer.WriteLine ("226 Directory send Ok");
395                                 writer.Flush ();
396                                 if (!EndConversation (writer, reader)) {
397                                         client.Close ();
398                                         return;
399                                 }
400                                 client.Close ();
401                         }
402                 }
403
404                 class ServerDeleteFile : FtpServer {
405                         protected override void Run ()
406                         {
407                                 Socket client = control.Accept ();
408                                 NetworkStream ns = new NetworkStream (client, false);
409                                 StreamWriter writer = new StreamWriter (ns, Encoding.ASCII);
410                                 StreamReader reader = new StreamReader (ns, Encoding.UTF8);
411                                 if (!DoAnonymousLogin (writer, reader)) {
412                                         client.Close ();
413                                         return;
414                                 }
415
416                                 if (!DoInitialDialog (writer, reader, "/home/someuser", "/home/someuser/")) {
417                                         client.Close ();
418                                         return;
419                                 }
420
421                                 string str = reader.ReadLine ();
422                                 if (str.Trim () != "DELE file.txt") {
423                                         Where = "DELE - " + str;
424                                         client.Close ();
425                                         return;
426                                 }
427                                 writer.WriteLine ("250 Delete operation successful");
428                                 writer.Flush ();
429                                 if (!EndConversation (writer, reader)) {
430                                         client.Close ();
431                                         return;
432                                 }
433                                 client.Close ();
434                         }
435                 }
436
437                 class ServerDownload : FtpServer {
438
439                         string Pwd, Cwd;
440
441                         public ServerDownload ()
442                                 : this (null, null)
443                         {
444                         }
445
446                         public ServerDownload (string pwd, string cwd)
447                         {
448                                 Pwd = pwd ?? "/home/someuser";
449                                 Cwd = cwd ?? "/home/someuser/";
450                         }
451
452                         protected override void Run ()
453                         {
454                                 Socket client = control.Accept ();
455                                 NetworkStream ns = new NetworkStream (client, false);
456                                 StreamWriter writer = new StreamWriter (ns, Encoding.ASCII);
457                                 StreamReader reader = new StreamReader (ns, Encoding.UTF8);
458                                 if (!DoAnonymousLogin (writer, reader)) {
459                                         client.Close ();
460                                         return;
461                                 }
462
463                                 if (!DoInitialDialog (writer, reader, Pwd, Cwd)) {
464                                         client.Close ();
465                                         return;
466                                 }
467
468                                 string str = reader.ReadLine ();
469                                 if (str != "PASV") {
470                                         Where = "PASV";
471                                         client.Close ();
472                                         return;
473                                 }
474
475                                 IPEndPoint end_data = (IPEndPoint) data.LocalEndPoint;
476                                 byte [] addr_bytes = end_data.Address.GetAddressBytes ();
477                                 byte [] port = new byte [2];
478                                 port[0] = (byte) ((end_data.Port >> 8) & 255);
479                                 port[1] = (byte) (end_data.Port & 255);
480                                 StringBuilder sb = new StringBuilder ("227 Passive (");
481                                 foreach (byte b in addr_bytes) {
482                                         sb.AppendFormat ("{0},", b);    
483                                 }
484                                 sb.AppendFormat ("{0},", port [0]);     
485                                 sb.AppendFormat ("{0})", port [1]);     
486                                 writer.WriteLine (sb.ToString ());
487                                 writer.Flush ();
488
489                                 str = reader.ReadLine ();
490                                 if (str != "RETR file.txt") {
491                                         Where = "RETR - " + str;
492                                         client.Close ();
493                                         return;
494                                 }
495                                 writer.WriteLine ("150 Opening BINARY mode data connection for blah (n bytes)");
496                                 writer.Flush ();
497
498                                 Socket data_cnc = data.Accept ();
499                                 byte [] dontcare = new byte [1];
500                                 data_cnc.Receive (dontcare, 1, SocketFlags.None);
501                                 data_cnc.Close ();
502                                 writer.WriteLine ("226 File send Ok");
503                                 writer.Flush ();
504                                 if (!EndConversation (writer, reader)) {
505                                         client.Close ();
506                                         return;
507                                 }
508                                 client.Close ();
509                         }
510                 }
511
512                 class ServerPut : FtpServer {
513                         public List<byte> result = new List<byte> ();
514                         
515                         protected override void Run ()
516                         {
517                                 Socket client = control.Accept ();
518                                 NetworkStream ns = new NetworkStream (client, false);
519                                 StreamWriter writer = new StreamWriter (ns, Encoding.ASCII);
520                                 StreamReader reader = new StreamReader (ns, Encoding.UTF8);
521                                 if (!DoAnonymousLogin (writer, reader)) {
522                                         client.Close ();
523                                         return;
524                                 }
525
526                                 if (!DoInitialDialog (writer, reader, "/home/someuser", "/home/someuser/uploads/")) {
527                                         client.Close ();
528                                         return;
529                                 }
530
531                                 string str = reader.ReadLine ();
532                                 if (str != "PASV") {
533                                         Where = "PASV";
534                                         client.Close ();
535                                         return;
536                                 }
537
538                                 IPEndPoint end_data = (IPEndPoint) data.LocalEndPoint;
539                                 byte [] addr_bytes = end_data.Address.GetAddressBytes ();
540                                 byte [] port = new byte [2];
541                                 port[0] = (byte) ((end_data.Port >> 8) & 255);
542                                 port[1] = (byte) (end_data.Port & 255);
543                                 StringBuilder sb = new StringBuilder ("227 Passive (");
544                                 foreach (byte b in addr_bytes) {
545                                         sb.AppendFormat ("{0},", b);    
546                                 }
547                                 sb.AppendFormat ("{0},", port [0]);     
548                                 sb.AppendFormat ("{0})", port [1]);     
549                                 writer.WriteLine (sb.ToString ());
550                                 writer.Flush ();
551
552                                 str = reader.ReadLine ();
553                                 if (str != "STOR file.txt") {
554                                         Where = "STOR - " + str;
555                                         client.Close ();
556                                         return;
557                                 }
558                                 writer.WriteLine ("150 Ok to send data");
559                                 writer.Flush ();
560
561                                 Socket data_cnc = data.Accept ();
562                                 var datastr = new NetworkStream (data_cnc, false);
563                                 int ch;
564                                 while ((ch = datastr.ReadByte ()) != -1){
565                                         result.Add ((byte)ch);
566
567                                 }
568                                 data_cnc.Close ();
569                                 writer.WriteLine ("226 File received Ok");
570                                 writer.Flush ();
571                                 if (!EndConversation (writer, reader)) {
572                                         client.Close ();
573                                         return;
574                                 }
575                                 client.Close ();
576                         }
577                 }
578
579                 abstract class FtpServer {
580                         protected Socket control;
581                         protected Socket data;
582                         protected ManualResetEvent evt;
583                         public string Where = "";
584
585                         public FtpServer ()
586                         {
587                                 control = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
588                                 control.Bind (new IPEndPoint (IPAddress.Loopback, 0));
589                                 control.Listen (1);
590                                 data = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
591                                 data.Bind (new IPEndPoint (IPAddress.Loopback, 0));
592                                 data.Listen (1);
593                         }
594
595                         public void Start ()
596                         {
597                                 evt = new ManualResetEvent (false);
598                                 Thread th = new Thread (new ThreadStart (Run));
599                                 th.Start ();
600                         }
601
602                         public void Stop ()
603                         {
604                                 evt.Set ();
605                                 data.Close ();
606                                 control.Close ();
607                         }
608
609                         // PWD, CWD and TYPE I (type could be moved out of here)
610                         protected bool DoInitialDialog (StreamWriter writer, StreamReader reader, string pwd, string cwd)
611                         {
612                                 string str = reader.ReadLine ();
613                                 if (!str.StartsWith ("OPTS utf8 on")) {
614                                         Where = "OPTS utf8 - " + str;
615                                         return false;
616                                 }
617                                 writer.WriteLine ("200 Always in UTF8 mode"); // vsftpd
618                                 writer.Flush ();
619                                 str = reader.ReadLine ();
620                                 if (!str.StartsWith ("PWD")) {
621                                         Where = "PWD - " + str;
622                                         return false;
623                                 }
624                                 writer.WriteLine ("257 \"{0}\"", pwd);
625                                 writer.Flush ();
626                                 str = reader.ReadLine ();
627                                 if (str != ("CWD " + cwd)) {
628                                         Where = "CWD - " + str;
629                                         return false;
630                                 }
631                                 writer.WriteLine ("250 Directory changed");
632                                 writer.Flush ();
633                                 str = reader.ReadLine ();
634                                 if (str != ("TYPE I")) {
635                                         Where = "TYPE - " + str;
636                                         return false;
637                                 }
638                                 writer.WriteLine ("200 Switching to binary mode");
639                                 writer.Flush ();
640                                 return true;
641                         }
642
643                         protected bool EndConversation (StreamWriter writer, StreamReader reader)
644                         {
645                                 string str = reader.ReadLine ();
646                                 if (str != "QUIT") {
647                                         Where = "QUIT";
648                                         return false;
649                                 }
650                                 writer.WriteLine ("220 Bye");
651                                 writer.Flush ();
652                                 Thread.Sleep (250);
653                                 return true;
654                         }
655
656                         protected bool DoAnonymousLogin (StreamWriter writer, StreamReader reader)
657                         {
658                                 writer.WriteLine ("220 Welcome to the jungle");
659                                 writer.Flush ();
660                                 string str = reader.ReadLine ();
661                                 if (!str.StartsWith ("USER ")) {
662                                         Where = "USER";
663                                         return false;
664                                 }
665                                 writer.WriteLine ("331 Say 'Mellon'");
666                                 writer.Flush ();
667                                 str = reader.ReadLine ();
668                                 if (!str.StartsWith ("PASS ")) {
669                                         Where = "PASS";
670                                         return false;
671                                 }
672                                 writer.WriteLine ("230 Logged in");
673                                 writer.Flush ();
674                                 return true;
675                         }
676                         
677                         public IPAddress IPAddress {
678                                 get { return ((IPEndPoint) control.LocalEndPoint).Address; }
679                         }
680                         
681                         public int Port {
682                                 get { return ((IPEndPoint) control.LocalEndPoint).Port; }
683                         }
684
685                         protected abstract void Run ();
686                 }
687         }
688 }
689
690