Hack Forums
[C#] Tcp socket with proxy - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Tcp socket with proxy (/showthread.php?tid=4840086)



Tcp socket with proxy - OnlyQubes - May 28, 2015

Hello fellow Hackforums members.

I am looking for a way to connect to a tcp server (minecraft server in the current case) with a proxy.

Is there something like HttpWebRequest.Proxy for sockets? (HttpWebRequest example below)
PHP Code

<?php 
HttpWebRequest httpRquest 
= (HttpWebRequest)WebRequest.Create("random website");
            
httpRquest.Proxy = new WebProxy("proxy address"); 

Example of a socket class that needs connect to a server trough a proxy:
PHP Code

<?php 
class HFLookingForHelp
    
{
        static 
Socket mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        static 
byte[] buffer = new byte[1028];

        static 
void Main(string[] args)
        {
            
//mc.Koridorius.lt = server ip (minecraft server), 25565 = port of the minecraft server
            
ConnectToServer("mc.Koridorius.lt", 25565);
        }

        static 
void ConnectToServer(string ip, int port)
        {
            
mainSocket.BeginConnect(ip, port, new AsyncCallback(OnConnectedToServer), null);
        }

        static 
void OnConnectedToServer(IAsyncResult ar)
        {
            
Console.WriteLine("Connected to server.");

            
//Connected, begin reicing/sending bytes
        
}
    } 

I have heard about SOCKS5, but i'm not sure if it the right way to get sockets connect trough a proxy.


* - Bulldoozer1337 - May 28, 2015

SOCKS is just a protocol for proxy.

You can design your own protocol or use existing. If you can you should better develop your own protocol because SOCKS protocol is trash.

SOCKS protocol RFC:
ietf.org/rfc/rfc1928.txt

You have to write your own code.


* - phrootoo - May 28, 2015

I mean, I've never tried this before, but when you think it through it's actually somewhat complex.

Http works in a completely different way to TCP. Where TCP is always connected, Http is request based rather than stream based. Sure, you remember sessions, but if you're looking to have a constant connection open to another server, then relaying messages backwards and forwards, it's definitely far from as simple as setting a proxy up.

Actually, i'd be fairly interested in this project (Creating a ProxySocket system, although it would require a base server etc).


* - OnlyQubes - May 28, 2015

Okey got it.
Thank you very much for your answers.


* - Bulldoozer1337 - May 28, 2015

(May 28, 2015 08:22 AM)phrootoo Wrote:  I mean, I've never tried this before, but when you think it through it's actually somewhat complex.

Http works in a completely different way to TCP. Where TCP is always connected, Http is request based rather than stream based. Sure, you remember sessions, but if you're looking to have a constant connection open to another server, then relaying messages backwards and forwards, it's definitely far from as simple as setting a proxy up.

Actually, i'd be fairly interested in this project (Creating a ProxySocket system, although it would require a base server etc).

HTTP is a software-layer-protocol built upon TCP.

HTTP connects, sends everything it needs, receives response and closes connection because it doesn't need to do anything else.


* - OnlyQubes - May 28, 2015

(May 28, 2015 09:16 AM)Bulldoozer1337 Wrote:  HTTP is a software-layer-protocol built upon TCP.

HTTP connects, sends everything it needs, receives response and closes connection because it doesn't need to do anything else.

Didn't know that, thank you for the information. :)


* - phrootoo - May 29, 2015

(May 28, 2015 09:16 AM)Bulldoozer1337 Wrote:  HTTP is a software-layer-protocol built upon TCP.

HTTP connects, sends everything it needs, receives response and closes connection because it doesn't need to do anything else.

I am aware. I realise it was written a little incorrectly, but the fact that the connection is completely different means that its just not feasible in the way that a normal proxy works.


* - ༺La FLame༻ - May 29, 2015

I suggest you use an application like Proxifier for that purpose.