19 – 21 MARCH 2006 Riyadh, Saudi Arabia
Internet communication with Indy Olaf Monien IT Consultant
Internet Communication High level Web applications (aspx) Web services (asmx) Indigo aka WCF Low level Socket level TCP/IP – TCP, UDP, etc. Custom protocols
Low Level Communication What’s in the box? System.Net Alternatives Commercial 3rd party vendors
System.Net Core sockets System.Net.Sockets TcpClient, TcpListener, UdpClient Few ready to use protocols Sytem.Net WebClient FtpClient System.Net.Mail (.NET 2.0)
Indy Open Source Library Almost every known Internet protocol TCP, UDP, raw sockets Available for.NET and Win32 Pure.NET / C# port in the works
Available Client Protocols TCPClient, UDPClient, CmdTCPClient, IPMCastClient, IcmpClient, DayTime, DayTimeUDP, DICT, DNSResolver, Echo, EchoUDP, Finger, FSP, FTP, Gopher, HTTP, Ident, IMAP 4, IRC, LPR, NNTP, POP 3, QOTD, QOTDUDP, Rexec, RSH, SMTP, SMTPRelay, SNMP, SNPP, SNTP, SysLog, Systat, SystatUDP, Telnet, Time, TimeUDP, TrivialFTP, UnixTime, UnixTimeUDP, Whois
Available Server Protocols UDPServer, CmdTCPServer, SimpleServer, TCPServer, IPMCastServer, ChargenServer, ChargenUDPServer, DayTimeServer, DayTimeUDPServer, DICTServer, DISCARDServer, DiscardUDPServer, DNSServer, ECHOServer, EchoUDPServer, FingerServer, GopherServer, HTTPProxyServer, HTTPServer, IdentServer, IMAP 4 Server, IRCServer, MappedPOP 3, MappedPortTCP, MappedPortUDP, MappedTelnet, NNTPServer, POP 3 Server, QotdUDPServer, RexecServer, RSHServer, SMTPServer, SocksServer, SyslogServer, SystatServer, SystatUDPServer, TelnetServer, TimeServer, TimeUDPServer, TrivialFTPServer, UnixTimeServer, UnixTimeUDPServer, WhoIsServer
How Indy is Different Originally implemented in Pascal Certain uncommon syntax elements (TId …) Has, but does not rely on events Designed for threads Sequential programming High abstraction level Similar to building Unix clients / servers Like working with files
Code - Blocking File Write procedure TForm1.Button1Click(Sender: TObject); var s: string; begin s := 'Indy Rules the (Kudzu) World !' + #1310; try with TFileStream.Create('d:\temp\test.dat', fmCreate) do try WriteBuffer(s[1], Length(s)); finally Free; end; end;
Just like file access with TIdTCPClient.Create do try Host := 'news.atozedsoftware.com'; Port := 119; Connect; try // Read and write here finally Disconnect; end ; finally Free; end ;
Just like file access using (TCPClient LClient = new TCPClient()) { LClient.Host = "news.atozedsoftware.com"; LClient.Port = 119; LClient.Connect(); try { // Read and write here } finally { LClient.Disconnect(); }
Exceptions try Client.Connect; try // Perform read/write here finally Client.Disconnect; end ; except on E: EIdException do begin // Handle Indy exception here end ;
Exceptions try { LClient.Connect(); try { // Read and write here } finally { LClient.Disconnect(); } catch (EIdException e) { // Handle Indy exception here }
Send Mail Demo Simple Mail Client Construct and send a message Delphi and C#
TCP Server Events
Event Flow
Minimal Web Server Demo Simple, yet fully functional web server Delphi and C# Threaded
Eliza Demo More complex HTTP Server Interactive and Dynamic Maintains Session
Command Handlers
Command Handler Demo Just two commands Can add more
RBSOD Demo UDP Client and Server Useful Firewalls u/svchost.zip u/RBSOD.zip
Further Information Demos: Indy Website:
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY. Thank You!