Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6807671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:51:39+00:00 2026-05-26T19:51:39+00:00

I am attempting to build a simple C# TCP proxy for my business so

  • 0

I am attempting to build a simple C# TCP proxy for my business so I can block certain websites from my employees. All is well except I am having trouble seeing what website the user is trying to visit… I can see that the user has connected to my proxy server so I know I am getting connections but the OnRecieve callback isn’t even firing. Am I reading from the socket wrong?

Here is my code:

internal class AsyncState
{
    public const int BufferSize = 4096;
    public byte[] Buffer = new byte[AsyncState.BufferSize];
    public Socket Socket;
    public StringBuilder Content = new StringBuilder();
}

private void OnLoad(object sender, EventArgs e)
{
    IPAddress[] addressCollection = Dns.GetHostAddresses(Dns.GetHostName());
    foreach (IPAddress ipAddress in addressCollection)
    {
        if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
        {
            localEndPoint = new IPEndPoint(ipAddress, 8080);
            Console.WriteLine("Local IP address found... " + localEndPoint.ToString());
            break;
        }
    }

    isListening = true;

    thread = new Thread(new ThreadStart(
        delegate()
        {
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            serverSocket.Bind(localEndPoint);
            serverSocket.Listen(10);

            while (isListening)
            {
                resetEvent.Reset();

                Console.WriteLine("Waiting for clients...");
                serverSocket.BeginAccept(new AsyncCallback(OnAccept), serverSocket);

                resetEvent.WaitOne();
                }
            }));

        thread.Start();
    }
}

private void OnAccept(IAsyncResult result)
{
    resetEvent.Set();

    Socket clientSocket = (result.AsyncState as Socket).EndAccept(result);
    Console.WriteLine("Client has connected... " + clientSocket.RemoteEndPoint.ToString());

    AsyncState state = new AsyncState();
    state.Socket = clientSocket;
    state.Socket.BeginReceive(state.Buffer, 0, AsyncState.BufferSize, SocketFlags.None, new AsyncCallback(OnRecieve), state);
}

private void OnRecieve(IAsyncResult result)
{
    AsyncState state = result.AsyncState as AsyncState;

    int totalRead = state.Socket.EndReceive(result);
    if (totalRead > 0)
    {
        state.Content.Append(Encoding.ASCII.GetString(state.Buffer, 0, totalRead));
        state.Socket.BeginReceive(state.Buffer, 0, AsyncState.BufferSize, SocketFlags.None, new AsyncCallback(OnRecieve), state);
    }
    else
    {
        if (state.Content.Length > 1)
            Console.WriteLine("Message recieved from client... " + state.Content.ToString());

        state.Socket.Close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:51:39+00:00Added an answer on May 26, 2026 at 7:51 pm

    Building a well working proxy is no simple task as you will have to understand and handle HTTP etc. in both directions…

    I would recommend to either use an existing library for that OR some configurable proxy…

    • http://www.mentalis.org/soft/projects/proxy/ (with source)
    • http://sourceforge.net/p/portfusion/home/PortFusion/ (with source)
    • http://www.wingate.com/
    • http://www.squid-cache.org/

    REMARK:

    I don’t know in which jurisdiction you are but using such technology without knowledge/consent of employees can in some places be a problem…

    Another point: Instead of using such methods I would tell the employee to stop abusing the internet connection of the company 1-3 times and if that doesn’t work I would rather fire that person… such employees is not only abusing the internet connection of the company but in worstcase is putting the company at risk (virus/trojan etc.) and also defrauding the company (if he does this in work hours)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to build a simple method that creates an XML file from
I'm attempting to build a simple plugin like this (function($) { $.fn.gpSlideOut = function(options,
I'm attempting to build a method call from strings that have been passed into
I am attempting to build a backup script that moves a tar file from
I'm attempting to build Python 2.6.2 from source on my Linux system. It has
I am attempting to build a simple WPF Application using msbuild via a custom
I'm attempting to build a very simple wxPython GUI that monitors and displays external
I am attempting to build a simple content management system using Twitter's Bootstrap for
I'm not sure if I'm using classes correctly. I'm attempting to build a simple
I am attempting to build a simple OpenGL 3.2 program which consists of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.