Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Programming Tutorials › [Neutral] Concepts about Socket Programming

[Neutral] Concepts about Socket Programming

Posts 1–3 of 3 · Page 1 of 1
♪~ ᕕ(ᐛ)ᕗ
♪~ ᕕ(ᐛ)ᕗ
[Neutral] Concepts about Socket Programming
Hello my fellow MPGHians.

I was bored so I decided to make a tutorial or something here...Alright this tutorial is dedicated to those who are looking forward to make a socket-based application or a server.

I'm assuming that you already know part of/all the basics of programming. For this tutorial I am going to use C# .NET.


1.Sockets in short words (just saying but they ain't that short)
Let's take for an example two phones.
Phone 1 - Listening machine (which listens for incoming calls)
Phone 2 - Client machine (which calls the listener)

If you've put your logic on work you probably might got what I am trying to say from now, otherwise continue reading....
Just like the phone2 calls the phone1 which displays the caller info on the screen, sockets connects to each others. (Without throwing events, although it's still possible to add events so you can get the clients which connects/sends data info easier)
We can declare a Socket and make several usages of it, a socket can listen for incoming connections (a listener socket) or can send a buffered data (a client socket) to a listener, but we cannot use a socket as a client and a listener one at the same time. (if you know what I mean)

A Client Socket is able to make 2 operations and then it won't be used anymore. (well yeah you can actually 'reload' it and make it reusable)

This is what I'm talking about:


The Socket.Send() and Socket.Receive() operations are made by accessing the client socket's stream and reads/writes on it. The thing that you have to keep in mind is that we don't want to make ourselves feel uncomfortable while programming so I am not going to cover a detailed way on how to have a direct access to the client's stream. (Even if it's easy....new NetworkStream(SocketClient),,,,blablabla)

Here's a cute pic of a bunny:


Every time that we connect a socket to a listener one we send the information about the socket to the listener. And the listener receives it by calling Socket.AcceptSocket() on a loop.

Ex:
Code:
private void run_server()
{
     ListenerSocket.Bind((EndPoint)(new IPEndPoint(IPAddress.Any, 8888))); //binds the socket to a port on the machine
     ListenerSocket.Listen(0); //puts the socket on a listening state
     while(true)
     {
             Socket client = ListenerSocket.AcceptSocket(); //receives the class of a newly connected socket
             ...Code...
      }
}
So this is pretty much how can the listener access the client's stream.

Now this is Kim Kardashian's Sex Tape:


Quote Originally Posted by Notes
1.When we call the Socket.Receive() function the thread on which the call was performed is going to be paused until we receive a buffer contain some data.
2.Every time that we send some data to the listener, we have to make sure that the listener is going to receive it. So every Socket.Send() function in a client must be followed by a ClientSocket.Receive() function in the listener. (The same thing applies for the client too)
Now if you keep working with Sockets you might understand this better because experience is the key to success.


2.Fundamental concepts about our applications
Everything that I am going to explain here depends on what we are trying to do with our application.

There are peeps who might just want do receive a certain info about something from the server, but there are others who wants to do more complex things like sending personal info to the server (things that a normal String cannot support).

To make sure that not every Socket is able to receive our info we are going to use some special commands that our listener will recognize and will work on them.

Example:
I want to receive a information about a file which is stored on the server, what should I do? Well first of all we have to create (imagine) a special command that our server will recognize....I am going to use:
Code:
/getInfo [FileName]
ex:
/getInfo D:\Chicken.txt
When the server reads the data that we sent it will recognize our command and will extract the file name and then send its info to the client...This is a hand-made code for the client stuff:
Code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;


public class Something
{
     Socket s = new Socket(...);

     public Something()
     {
        s.Connect("HostIP", 4444); //4444 - Server Port
     }

     public string GetFileInfo(string file)
     {
         if(!s.Connected) //Check if the socket is connected or not...
           return "Error: Socket isn't connected!";
         s.Send(Encoding.ASCII.GetBytes("/getInfo " + file)); //Sends the data as an array of bytes
         
         byte[] received_bytes = new byte[300]; //The array which will store the data that we are going to receive from the server.....
         s.Receive(received_bytes);

         string data = Encoding.ASCII.GetString(received_bytes).Trim(new char[] {'\0'});
         return data;

         /* NOTE */
         /*The size of the data that we are going to receive might be smaller than the size of our storing array. If that's the case and we are trying to receive a string we must Trim it.*/
     }
}
And here is the listener stuff:

Code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System****;


public class SomethingServer
{
     Socket s = new Socket(...);

     public SomethingServer()
     {
        //We want a listening Socket
        s.Bind((EndPoint)(new IPEndPoint(IPAddress.Any, 8888)));
        s.Listen(0);
     }

     private void run_server()
     {
        while(true)
        {
            Socket client = s.AcceptSocket();
            byte[] data_from_client = new byte[300];
            client.Receive(data_from_client);
            string cmd = Encoding.ASCII.GetString(data_from_client).Trim(new char[] {'\0'});

            if(cmd.Contains("/getInfo"))
            {
               byte[] data_to_send = new byte[0];
               if(!File.Exists(cmd.Replace("/getInfo ", "")))
                  data_to_send = Encoding.ASCII.GetBytes("Error: File does not exists!");

               data_to_send = File.ReadAllBytes(cmd.Replace("/getInfo ", ""));
               client.Send(data_to_send);
            }
        }
     }

     public void Run()
     {
        (new Thread(new ThreadStart(run_server))).Start();
     }
}
In the next tutorial I will explain how to make it more advanced and even more professional.
#1 · 14y ago
KI
kibbles18
i like the first picture
#2 · 14y ago
♪~ ᕕ(ᐛ)ᕗ
♪~ ᕕ(ᐛ)ᕗ
well thank you
#3 · 14y ago
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

  • About hack programming...By skatebone in C++/C Programming
    5Last post 17y ago
  • Socket Programming helpBy itouchlover in C# Programming
    7Last post 15y ago
  • C++ socket programmingBy Revultra in C++/C Programming
    5Last post 15y ago
  • Question about a programBy jeffchan666 in Combat Arms Hacks & Cheats
    5Last post 17y ago
  • wanting someone to interview about computer language programming!By azhuuuuu in Coders Lounge
    7Last post 15y ago

Tags for this Thread

None