To make an actual connection to the server, we need to inherit the Session class, which provides us with methods to receive and send data to a connection (whether it's local or remote). That means we will have to create two classes. One for the client, so we can accept the MapleStory's connection and send packets from it to the server - and one for the server, so we can connect to the server and send packets from it to the client.
We will start with the Server. Don't forget to inherit the Session class and import your Connection folder.
Click for Image.
There are 3 base constructors for the Session class. We will be using the one that accepts arguments of an IP, a Port and a Type Name. The Type Name is a name given for a Session to differ it from others, to make it more organized. I created the class and just used the keyword base to connect to the given IP and Port. I used the Type Name "Server", of course. I also imported some of the methods of the inherited class:
OnDisconnect, which is called when the server is disconnected (Manually or not),
OnPacketInbound, which is called when a packet is received from the server, and
OnHandshakeInbound, which is called when the Handshake packet is received from the Server.
Click for Image.
To access the Server's instance, we will need to store it somewhere. You can simply add a line in Program class to store it, making it static, of course.
Click for Image.
Client! That's the next class we will be making. Create this class, and on the constructor, the base requires a socket to be applied - add it in the argument of the constructor and also make a new instance of Program.Server.
The client's instance is created once a connection is accepted (MapleStory's original client). The moment we are creating a new Client instance, we are connecting to the server to make the actual bridge. Don't forget to add the base methods! No need for Handshake as we're not getting one..
Click for Image.
To accept a connection from the MapleStory client, we obviously need to listen on the desired port (8484). To do that, declare a static TcpListener variable, and add a method named Listen to start the listener and accept a new socket. Oh and.. don't foget the async EndAccept.
Click for Image.
We are creating a new TcpListener instance to listen for connections on Port 8484 from any IP (The MapleStory login port). The async callback will be EndAccept method, which will get the Socket from the listener and apply it to the new Client instance. You may also add debug messages, such as "Listening on Port 8484, Accepted connection on Port 8484" and so on.. Oh and! You're probably wondering what "Instance" is. It's just a variable of a Client so I can quickly access the instance from other classes (Just like what I did with the Server in Program class).