Hack Forums
[.NET] Async TcpClient Socket doesn't receive Data - 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: [.NET] Async TcpClient Socket doesn't receive Data (/showthread.php?tid=5397248)



Async TcpClient Socket doesn't receive Data - i-manuel - Sep 5, 2016

Hello, there are no errors but if i send some data to the client it wont the client don't receive it...

can anyon help(Ninja please don't help me or leave a comment)

Code


* - Ninja - Sep 5, 2016

https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.endconnect(v=vs.110).aspx

Just cast the AsyncState to a TcpClient object and go from there.


* - Josh‎ - Sep 6, 2016

(Sep 5, 2016 04:03 PM)Ninja Wrote:  https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.endconnect(v=vs.110).aspx

Just cast the AsyncState to a TcpClient object and go from there.

Damn it Ninja, he said for you not to help him 🤦‍♂ (Click to View)


* - Ninja - Sep 6, 2016

(Sep 6, 2016 02:14 AM)Josh‎ Wrote:  Damn it Ninja, he said for you not to help him 🤦‍♂ (Click to View)

Im bothered by retardation. People cant code and post sources of shitty code, I point it out.


* - Dianab0lical. - Sep 6, 2016

GitHub wouldn't load for me for some reason. But judging by the "ProxyScraper" git project in the URL, I'd assume you're trying to open web traffic to test a proxy with a TCPClient? If that's what you're trying to do then a TCPClient is over-engineering your solution.

Try this (**NOTE: This was done in notepad from memory, please ignore the ugly capitalization/inconsistent casing):
Code
    public sub Main()
        Dim Proxies as new List(Of WebProxy)
        
        'Load list of proxies here using Proxies.Add(new WebProxy("HOST:PORT", True))
        
        For Each Proxy as WebProxy in Proxies.ToArray()
            if ProxyWorks(Proxy) then
                'Working Proxy!
            else
                'Non-working Proxy!
            end if
        next
    End Sub
    
    public function ProxyWorks(Proxy as WebProxy) as Boolean
        dim ProxyTestClient as new WebClient()
        ProxyTestClient.Proxy = Proxy
        try
            if ProxyTestClient.DownloadString("URL") <> Nothing then
                return true
            end if
        catch Ex as Exception
            'Up to you if you'd like to do more complex error-handling here, e.g.: determine WHY the proxy failed, etc.
            return false
        end try
    end function

And if you want to get really fancy/clean with it, figure out how to do it all asynchronously! 🤝


* - Ninja - Sep 6, 2016

(Sep 6, 2016 11:06 AM)H4rdBeat Wrote:  GitHub wouldn't load for me for some reason. But judging by the "ProxyScraper" git project in the URL, I'd assume you're trying to open web traffic to test a proxy with a TCPClient? If that's what you're trying to do then a TCPClient is over-engineering your solution.

Try this (**NOTE: This was done in notepad from memory, please ignore the ugly capitalization/inconsistent casing):
Code
    public sub Main()
        Dim Proxies as new List(Of WebProxy)
        
        'Load list of proxies here using Proxies.Add(new WebProxy("HOST:PORT", True))
        
        For Each Proxy as WebProxy in Proxies.ToArray()
            if ProxyWorks(Proxy) then
                'Working Proxy!
            else
                'Non-working Proxy!
            end if
        next
    End Sub
    
    public function ProxyWorks(Proxy as WebProxy) as Boolean
        dim ProxyTestClient as new WebClient()
        ProxyTestClient.Proxy = Proxy
        try
            if ProxyTestClient.DownloadString("URL") <> Nothing then
                return true
            end if
        catch Ex as Exception
            'Up to you if you'd like to do more complex error-handling here, e.g.: determine WHY the proxy failed, etc.
            return false
        end try
    end function

And if you want to get really fancy/clean with it, figure out how to do it all asynchronously! 🤝
This has to be the worst way to test proxies ever.


* - Dianab0lical. - Sep 15, 2016

(Sep 6, 2016 12:04 PM)Ninja Wrote:  This has to be the worst way to test proxies ever.

Appreciate your feedback.