Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 17:31

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[TuT][C#]Creating your own proxy - Part 2

Discussion on [TuT][C#]Creating your own proxy - Part 2 within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
[TuT][C#]Creating your own proxy - Part 2

Part 1:

The Client Socket
Quote:
  • Client Logic
  • Connection
  • Testing
Client Logic
So now that we have been looking at server-side programming, then we will look at client-side programming. I will explain basic things about the client and then how we code the connection for a client etc. There won't be so much content in this part of the tutorial, because pretty much a lot of it has already been covered in the first part of the tutorial, which is server-side programming, but there is still a few things that you should be aware of etc.

First of all open up the current solution, in my case "ProxyExample_Server", however once it's been opened, then create a new project, which should be the client. I will call mine "ProxyExample_Client".

Basically we have already created our clientsocket, except one thing. The SocketClient class from the server can be used here in exactly same way, there is only a minor difference. We need to switch EndAccept out with a new method called Connect.

This connect method should contain 2 parameters. A string as IPAddress and an int as port. Within this method the Socket is created and connecting to a specific endpoint calling Socket.Connect() and that's basically the difference of a server-side client and an actual client.

Now there is some logic behind a client tho. The client should not run a lot checks etc. it is the server that should check for things. The client should send data to the server, the server handles the data and sends it back to the client or new data, the client then handles the new data. The way the client should handle data it receives is not by modifying it like the server, but displaying it to the user.

An example could be a chat.

User input "Hello World!"
Client sends "Hello World!" to the server
Server checks if it's a valid message
If the message is valid it sends it to the other Clients
The clients displays the text "Hello World!"

It's a really simple way of explaining it and there is a lot more backwards how a client work, but it's important that you should just understand a client is not handling things, but more like sending inputs and displaying.

Just like your PC works, it has a system which is running in the background, which handles all the input you give it as a user.
If you switch the system out with the server and the user out with the client, then it is basically same way this works.

I might said it a bit wrong or confusing, but I hope you get it.

Connection
Now let's get to the coding part with the connect.
I assume you by now have modified the SocketClient and created the connect method already. The connect method should also have a try/catch block and be a bool, return false in catch, otherwise return true. It's used to check if the client has connected.
Code:
        public bool Connect(string IP, int Port)
        {
            ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                ClientSocket.Connect(new IPEndPoint(IPAddress.Parse(IP), Port));
                return true;
            }
            catch
            {
                return false;
            }
        }
Now let's use this. We do not need a connect event as it will connect in the main method in our case, however if it was a real client with login etc. it would probably be in the login buttons event, but we need a receive and a disconnect event.

You already know how the event works from the server tutorial, so it's basically just creating them again.
Code:
        static void OnDisconnection(SocketClient sClient)
        {
            Console.WriteLine("The client has been disconnected...");
            try
            {
                if (sClient.ClientSocket.Connected)
                    sClient.ClientSocket.Disconnect(false);
            }
            catch
            {
            }
        }
        static void OnReceive(SocketClient sClient, byte[] Buffer)
        {
            Console.WriteLine("The client has received data from the server...");

            foreach (byte b in Buffer)
                Console.Write(b + "\t");
            Console.Write("\n\n\n");
        }
Now we just need to create the connect, which we will just do in the main method. After that we will make a while loop and then put a Console.ReadLine() and for every time we press enter we will just send a small data packet with some numbers to the server. We should then receive the packet back from the server and then displays it as shown above in the receive event.

First we call the connect method.
Code:
SocketClient client = new SocketClient();
client.Connect("127.0.0.1", 7788);
However as it's a bool then we wrap an if check around it.
Code:
            SocketClient client = new SocketClient();
            if (client.Connect("127.0.0.1", 7788))
            {
                Console.WriteLine("Success!!");
            }
            else
            {
                Console.WriteLine("Failed to connect to the server...");
                Console.ReadLine();
            }
Now we call the BeginReceive method as we want to be able to receive packets from the server. We also need to set the 2 events for disconnection and receive.
Code:
                client.onDisconnection = new ConnectionEvent(OnDisconnection);
                client.onReceive = new BufferEvent(OnReceive);
                client.BeginReceive();
Then we create the while loop and put a Console.ReadLine in the top of it.
Code:
                while (true)
                {
                    Console.ReadLine();
                }
After the ReadLine we will just create a packet with some numbers. It's up to you what size you want to give your packet and what numbers etc. However this is my packet.
Code:
byte[] packet = new byte[10];
                    for (int i = 0; i < 10; i++)
                        packet[i] = (byte)i;
When that's done we just call the Send method.
Code:
client.Send(packet);
This should be the final main method.
Code:
        static void Main(string[] args)
        {
            SocketClient client = new SocketClient();
            if (client.Connect("127.0.0.1", 7788))
            {
                Console.WriteLine("Success!!");

                client.onDisconnection = new ConnectionEvent(OnDisconnection);
                client.onReceive = new BufferEvent(OnReceive);
                client.BeginReceive();

                while (true)
                {
                    Console.ReadLine();
                    byte[] packet = new byte[10];
                    for (int i = 0; i < 10; i++)
                        packet[i] = (byte)i;

                    client.Send(packet);
                }
            }
            else
            {
                Console.WriteLine("Failed to connect to the server...");
                Console.ReadLine();
            }
        }
Testing
Now we need to test it, but as default VS will only have one main project, so we need to set both the server and the client to start up on debug.

Right click your solution and then properties.

Choose "Multiple startup projects:" and then just make both the projects to "Start".

Now debug and test if the client/server works with each other.

As you can see it should work just perfect and display like below.



That's it for now, good luck and see you in part 3 where we will look at proxy logic.
The last part which will be part 4 we create a basic proxy between our now coded client and server.

However now you should be able to figure most of it out yourself as a proxy is basically a server for the client and a client for the server, then it's most likely about logical thinking.
I don't have a username is offline  
Thanks
3 Users
Old 01/25/2012, 11:03   #2
 
elite*gold: 0
Join Date: Apr 2009
Posts: 101
Received Thanks: 1
Good work we are waiting part 3
koko20 is offline  
Old 01/29/2012, 22:19   #3
 
elite*gold: 0
Join Date: Jan 2012
Posts: 85
Received Thanks: 23

thx bro . part3 w8ing for it =)
Heroka is offline  
Old 02/03/2012, 11:18   #4
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by koko20 View Post
Good work we are waiting part 3
I will make part 3 later today Maybe part 4 if I can find time for it.
I don't have a username is offline  
Old 02/03/2012, 14:44   #5
 
elite*gold: 0
Join Date: Jan 2012
Posts: 164
Received Thanks: 22
great tuts buddy im waiting part 3 , for who know some asm and need help in getting the dhkey/encryption and its alg. , give them a part 5 XD -not the current encryption but an old one just to learn how this goes - goodluck
injection illusion logic is offline  
Old 02/03/2012, 17:08   #6
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by injection illusion logic View Post
great tuts buddy im waiting part 3 , for who know some asm and need help in getting the dhkey/encryption and its alg. , give them a part 5 XD -not the current encryption but an old one just to learn how this goes - goodluck
There is no need for a part 5, because encryptions and packethandling are in a different category and there is already tutorials on that.
I don't have a username is offline  
Old 02/03/2012, 17:10   #7
 
elite*gold: 0
Join Date: Jan 2012
Posts: 164
Received Thanks: 22
*cough* never knew about that other category , well where it exist o-0 like gimme tags or links or location need to read them badly
injection illusion logic is offline  
Old 02/03/2012, 17:11   #8
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Pro4nevers threads.
I don't have a username is offline  
Old 02/06/2012, 23:59   #9
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
Just for general knowledge, if one has learnt of how to write a simple client/server program as shown above, he can easily move on to a Simple HTTP-server.

Since http is built on top of tcp/ip, the program shown above can serve as a retarded http server.


To test,
start the server
type in localhost:7788 into address bar and hit enter (port number quoted from the above example)

you should see some weird output in your browser. The only reason for not seeing 0-9 is because the browser is comprehending it as ASCII codes and not integers.
shitboi is offline  
Old 02/07/2012, 08:33   #10
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Argh, haven't got much time to finish the 3rd part, but some what half way I guess. Been quite busy atm. I apologize for the delay.
I don't have a username is offline  
Old 02/07/2012, 08:58   #11
 
m7mdxlife's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 920
Received Thanks: 3,514
Quote:
Originally Posted by I don't have a username View Post
Argh, haven't got much time to finish the 3rd part, but some what half way I guess. Been quite busy atm. I apologize for the delay.


your apology is not accepted!!
m7mdxlife is offline  
Old 02/07/2012, 10:15   #12
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
I wouldn't care if it was or not anyway xD
I don't have a username is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[TuT][C#]Creating your own proxy - Part 1
02/07/2012 - CO2 Programming - 17 Replies
First of all, I will not target Conquer, but just how a proxy works in general with connection etc. I will cover 4 things in this tutorial. Server sockets, Client sockets, proxy logic and then the actual creation of a proxy. Why do I cover the server and client thing? Because a proxy will be a middle man, so it will have both advantages as a client and a server. For the client it is a server, for the server it is a client. I will not show how to deal with packets, modifying them, structure them...
[Release] New proxy for creating 2moons accaunt(other country)
12/09/2008 - Dekaron Exploits, Hacks, Bots, Tools & Macros - 13 Replies
So i saw few topics about changing Ip and things like that to create acc. if u r not from USA. Here is proxy that works for me every time :) PHYLTERSHEKAN - HOMEPAGE http://i233.photobucket.com/albums/ee213/7kiramez ak7/proxy.jpg then just press RUN or SAVE FILE :cool:
Creating My Own Proxy
05/18/2007 - Conquer Online 2 - 14 Replies
Ok, so I'm posting this here because it's more of a question thread for any of the proxy developers out there. I am attempting to make my own proxy using auto it and have been successful in logging in, however, when I close the sockets the connection remains. I changed my Server.dat to send to 127.1.1.1 and my script takes the clients packets and sends them to the CO server and takes the CO servers responses and sends them to the client. I have ran my script and connected, I have ran the CO...
Creating forum Ip Proxy
11/14/2006 - CO2 Guides & Templates - 2 Replies
Have you been banned from the Offical Conquer Online forums or just want to rage their forums with Tubgirl or goatse or maybe even gay buttsechs? I'll tell you how in this simple tutorial 1) Get a proxy. You can find a list of proxy ips from this site http://www.samair.ru/proxy/ <--- Checking if the Ip works and how fast it is 2) to check to see if the ip is up navigate to



All times are GMT +2. The time now is 17:31.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.