So you have MMF 1.5, and seen the MooSock object in the insert new object dialog, and if you are like me you will have said “Oh I wonder what that is”, thinking it is a new version of the MOO object, only to look at it and notice it isn’t. Well it is in a way, except it lets you communicate with any internet server (of any type http, ftp, IRC, etc), or make your own internet server (with a fair amount of work), so instead of communicating only with MOO servers this lets you use other internet protocols.

Of course I didn’t realize this at first, but after a short trip to www.3ee.com I suddenly realized how useful this object was, it gave MMF an easy to use interface to the Winsock.dll (what Windows uses to communicate over TCP/IP) that comes with Windows. The MooSock object is very similar to the MS Winsock Active X Control that comes with Visual Basic 6, which can not be used in MMF because of the way MMF’s Active X object works.

So now we have established that MooSock has nothing to do with cotton footwear for cows, let’s get down to the main point of this article, how to make a telnet client with MooSock.

1. To start with load MMF 1.5
2. Start a new application and goto the level editor
3. Add a MooSock object. 4 edit boxes, 1 for the server’s address (server), 1 for the server’s port (port), 1 for any replies from the server (messages) and 1 for you to type commands in (sendtoserver). 2 buttons, 1 for a connect/disconnect button (connect) and 1 to send commands to the server (send). You will also need a string object which only has an enter character, this can be achieved by editing the string deleting any text in the first paragraph and pressing enter (crlf).
4. Goto the events editor.
5. First we need to make a way for the user to connect/disconnect to/from a server.
For this we need two conditions
X = Negate
To connect
Condition:

X MooSock (MooSock): Is connected
+ Button (connect) clicked

Events:
MooSock: Connect to EditText$(“server”) on port Edit Value(“port”)

To Disconnect
Condition:

MooSock (MooSock): Is connected
+ Button (connect) clicked

Events:
MooSock: Disconnect

Simple? Yes, good. Now we need to inform the user when they are connected and disconnected from the server by displaying the messages Connected and Disconnected. We also need to change the text on the Connect/Disconnect button.
This is done like this;

When Connected
Condition:

MooSock(MooSock): On Connect

Events:

connect: Change text to “Disconnect”
messages: Set Text Edittext$( messages ) + paragraph$( crlf, paragraph( crlf ) ) + Connected + paragraph$( crlf , paragraph( crlf ) )

When Disconnected
Condition:

MooSock(MooSock): On Disconnect

Events:

connect: Change text to “Connect”
messages: Set Text Edittext$( messages ) + paragraph$( crlf, paragraph( crlf ) ) + Disconnected + paragraph$( crlf , paragraph( crlf ) )

Ok now our client can connect to a server and disconnect to a server, that’s all fine but it’s pointless if you can’t talk to the server now isn’t it?

To send to the server
Condition:

Button(send) is clicked
+ Edittext$(“sendtoserver”) <> “”

Events:

MooSock: Send Text Line Edittext$(“sendtoserver”)
messages: Set text Edittext$( messages ) + paragraph$( crlf, paragraph( crlf ) ) + > + Edittext$( sendtoserver )
sendtoserver: Set Text “”

Now don’t go rushing off to test it yet. Well you could but you may not get very far as you have not told it to receive any data from the server.

To receive:

Condition:

MooSock: On Received

Events:

messages: Set text Edittext$( “messages ) + paragraph$( crlf, paragraph( crlf ) ) + RecvLine$( MooSock )
messages: Scroll To End


There you go it should now! To test we will connect to a pop3 mail server and read some mail. To do this you will need to know your pop3 servers address (something like mail.isp.com) its port (standard is 110) your account name (normally the part in front of the @) and your account password. Also you will need a direct connection to the internet (a proxy may work if configured to allow traffic through on port 110). We will be using these common pop3 commands

user <username> :Sends the server your username to login.
pass <password> :Sends your password to the server to logon
list :Lists the E-mails stored on the server
retr <msg#> : Displays an email
quit :Logs you off and closes connection

http://pages.prodigy.net/michael_santovec/pop3telnet.htm has a better description of these commands plus others. For this test I will be using the mail server mail.gethyper.co.uk which runs on port 110.

1. Run the client
2. Enter your mail server’s address and port number in the respective edit boxes and click Send.
3. The server should respond with a line like this,

+OK <48002.1032367118@server5.donhost.co.uk>

4. This means you have connected to your server. Now you can log in.
5. Type user followed by your username like so,

user gethyper-mark

Now click send again.
6. If every thing is ok the server will respond by sending +OK (or a string starting with +OK)
7. You now send your password using the pass command like so,

pass letmein1234

8. If your username and password are correct the server will again respond with +OK (also may be followed by further information)
9. Now type list and click send the server will respond with a list similar to this one,

+OK
1 4565
2 8159
.

This shows that I have 2 E-mails waiting and the size of both, this list will vary depending on how many emails are waiting.
10. To read an E-mail you type retr followed by the number of the E-mail you want to read so (using the above list) if I wanted to read the E-mail with a size of 4565 I would type,

retr 1

Followed by clicking on send. If the command was successful the server would return something like this,

+OK
Return-Path: <someone@somewhere.co.uk>
Delivered-To: someone@somewhere.co.uk
Received: (qmail 46092 invoked from network); 18 Sep 2002 16:37:55 -0000
Received: from unknown (HELO tungsten.btinternet.com) (194.73.73.81)
by server5.donhost.co.uk with SMTP; 18 Sep 2002 16:37:55 -0000
Received: from host*-*-*-*.in-addr.btopenworld.com ([*.*.*.*] helo=mark)
by tungsten.btinternet.com with esmtp (Exim 3.22 #
id 17rhpg-0002Og-00
for someone@somewhere.co.uk; Wed, 18 Sep 2002 17:37:45 +0100
Reply-To: <someone@somewhere.co.uk>
From: Mark Beazley <someone@somewhere.co.uk>
To: <someone@somewhere.co.uk>
Subject: Test
Date: Wed, 18 Sep 2002 17:39:24 +0100
Organization: Hyperware
Message-ID: <000001c25f31$f4665aa0$0200a8c0@Beazley>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary=----=_NextPart_000_0001_01C25F3A.5633EA60
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.2616
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
This is a multi-part message in MIME format.
------=_NextPart_000_0001_01C25F3A.5633EA60
Content-Type: text/plain;
charset=Windows-1252
Content-Transfer-Encoding: 7bit
This is a test for my MooSock client
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.386 / Virus Database: 218 - Release Date: 09/09/2002

------=_NextPart_000_0001_01C25F3A.5633EA60
Content-Type: text/html;
charset=Windows-1252
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<META HTTP-EQUIV=3DContent-Type CONTENT=3Dtext/html; =
charset=3DWindows-1252>
<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3DMicrosoft Word 10>
<meta name=3DOriginator content=3DMicrosoft Word 10>
</head>
<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:36.0pt'>
<div class=3DSection1>
<p class=3DMsoNormal><font size=3D2 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
10.0pt;font-family:Arial'>This is a test for my MooSock =
client<o></o></span></font></p>
</div>
</body>
</html>


<P><FONT SIZE=3D2>---

Outgoing mail is certified Virus Free.

Checked by AVG anti-virus system (http://www.grisoft.com).

Version: 6.0.386 / Virus Database: 218 - Release Date: 09/09/2002

</FONT> </P>
------=_NextPart_000_0001_01C25F3A.5633EA60--
.

Which is the source code for the E-mail, which may look a bit confusing but you can just about make out the E-Mail, also note how Outlook has sent both a plain text version of the email as well as the HTML version.
11. When you are finished just type quit and click Send.


I have had one problem with using MooSock as a telnet and that is that I can’t connect to a *Nix shell account, as I just get a couple of characters sent back when connecting.

I have uploaded a zip file containing this article, a txt file with a log showing me connecting to and reading a message of my mail server, the source code for the client, and source code for a slightly more advanced client made by my friend. The file can be downloaded from http://www.gethyper.co.uk/telnetc.zip .You will need MMF 1.5 to run the simple client and MMF 1.5 with the String Parser object for the more advanced client.

So until next time
See you later
Mark Beazley

Next Time: How to make a telnet server with MooSock