Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 client 设置socks5 proxy连接不成功,并且连接方式有问题 #770

Open
aadog opened this issue Dec 17, 2024 · 36 comments
Open

Comments

@aadog
Copy link

aadog commented Dec 17, 2024

`
using System.Buffers;
using System.Buffers.Binary;
using System.IO.Compression;
using System.Net;
using System.Text;
using SuperSocket.Client;
using SuperSocket.Client.Proxy;
using SuperSocket.ProtoBase;

namespace csharp_talkatone
{
public class MyFilter():FixedHeaderPipelineFilter(10){
protected override int GetBodyLengthFromHeader(ref ReadOnlySequence buffer)
{
Console.WriteLine("recv");
return 2;
}

    protected override StringPackageInfo DecodePackage(ref ReadOnlySequence<byte> buffer)
    {
        return new StringPackageInfo(){Key = $"test",Body = $"{Encoding.UTF8.GetString(buffer.Slice(10))}"};
    }
}
internal class Program
{
    static async Task Main(string[] args)
    {
        var serverIp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6291);
        var proxyIp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8889);

        
 
        var client = new EasyClient<StringPackageInfo>(new MyFilter()).AsClient();
        client.Proxy= new Socks5Connector(serverIp);
        client.Closed += (sender, e) =>
        {
            Console.WriteLine("close");
        };
        client.PackageHandler +=((sender,e) =>
        {
           Console.WriteLine(e.Body);
           return ValueTask.CompletedTask;
        });
        
        
        await client.ConnectAsync(proxyIp);
  
        Console.WriteLine("aaa");
      
        Console.WriteLine("Press any key to continue . . . ");
        Console.ReadKey(true);
        return;
    }
}

}
`

socks5连接不成功,并且为什么会建立两条连接,不是应该直接用socks5的ip发送认证包吗

@wj8400684
Copy link
Contributor

已经修复啦 使用最新构建的那个api添加到nuget就好了

@wj8400684
Copy link
Contributor

await client.ConnectAsync(serverIp);
Proxy= new Socks5Connector(proxyIp);
你也用错了应该是这样用的

@aadog
Copy link
Author

aadog commented Dec 18, 2024

大哥 还有ssl流也不生效,没有单独设置域名不带证书的格式

@wj8400684
Copy link
Contributor

看看你的代码

@aadog
Copy link
Author

aadog commented Dec 18, 2024

已经修复啦 使用最新构建的那个api添加到nuget就好了

大哥,拉我进qq群啊,这个使用2.0.0-beta.28最新发布版,仍然有问题

@aadog
Copy link
Author

aadog commented Dec 18, 2024

`
static async Task testSuperSocket()
{
var addressEndpoint = IPEndPoint.Parse("43.139.170.206:23498");
var proxyEndpoint = IPEndPoint.Parse("127.0.0.1:8889");
var c = new EasyClient(new TestFilter()).AsClient();
c.Proxy = new Socks5Connector(proxyEndpoint);
await c.ConnectAsync(addressEndpoint);
// c.StartReceive();

}
`

@wj8400684
Copy link
Contributor

ssl设置呢

@aadog
Copy link
Author

aadog commented Dec 18, 2024

还没设置ssl

@aadog
Copy link
Author

aadog commented Dec 18, 2024

static async Task testSuperSocket() { var addressEndpoint = IPEndPoint.Parse("43.139.170.206:28218"); var proxyEndpoint = IPEndPoint.Parse("127.0.0.1:8889"); var clientBuild = new EasyClient<TalkAtonePacket>(new TestFilter()); clientBuild.Proxy = new Socks5Connector(proxyEndpoint); var c = clientBuild.AsClient(); c.PackageHandler += (a, b) => { Console.WriteLine("recv"); return ValueTask.CompletedTask; }; await c.ConnectAsync(addressEndpoint); c.StartReceive(); }
目前就是这样,然后会报错ConnectAsync,

System.ObjectDisposedException:“Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.”

@aadog
Copy link
Author

aadog commented Dec 18, 2024

如果使用dotnetty的话应该是这样,但是supersocket找不到相同的设置,似乎必须设置证书
pipeline.AddLast("tls", new TlsHandler( stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true), new ClientTlsSettings(connectInfo.Host)));

@wj8400684
Copy link
Contributor

image

@aadog
Copy link
Author

aadog commented Dec 18, 2024

谢谢大哥,不过socks5依然不行

@aadog
Copy link
Author

aadog commented Dec 18, 2024

走到这个位置就开始报错
image

@aadog
Copy link
Author

aadog commented Dec 18, 2024

image

@wj8400684
Copy link
Contributor

你去淘宝买一个sk5试试

@aadog
Copy link
Author

aadog commented Dec 18, 2024

你去淘宝买一个sk5试试

发给您试试是吗,稍等

@wj8400684
Copy link
Contributor

我这没问题的 你自己试试就行

@aadog
Copy link
Author

aadog commented Dec 18, 2024

我这没问题的 你自己试试就行

大哥,我确定socks5有问题,而且是代码问题,不会是s5服务器,因为相同的dotnetty运行很正常,而且各种客户端测试都没问题

@wj8400684
Copy link
Contributor

建议发demo

@aadog
Copy link
Author

aadog commented Dec 18, 2024

马上
csharp-talkatone.zip

@aadog
Copy link
Author

aadog commented Dec 18, 2024

socks5是本地使用charles点开的
image
image

@wj8400684
Copy link
Contributor

买个sk5测试吧 环境不一样测试不同

@aadog
Copy link
Author

aadog commented Dec 18, 2024

稍等一下,我购买个,绝对有问题

@aadog
Copy link
Author

aadog commented Dec 18, 2024

IP:14.29.214.198账户:123 密码:321 开通成功! Http端口:6677 S5端口:6688

@wj8400684
Copy link
Contributor

密码不对

@aadog
Copy link
Author

aadog commented Dec 18, 2024

稍等下大哥,我自己架设一个,买的连接有问题

@aadog
Copy link
Author

aadog commented Dec 18, 2024

...
8810

@aadog
Copy link
Author

aadog commented Dec 18, 2024

我也测试了hpsocket,dotnetty,确定都没有问题,就是supersocket这里的socket好像实现有点问题

@wj8400684
Copy link
Contributor

试试最新的

@kerryjiang
Copy link
Owner

Need test cases to cover this part.

@kerryjiang
Copy link
Owner

@aadog Hello, 请在myget上拿最新版本测试

@kerryjiang
Copy link
Owner

这玩意要升级起来做测试:
https://github.com/SuperSocket/SuperSocket.ProxyServer/tree/master

@kerryjiang
Copy link
Owner

Or other C# proxy server we can use for unit tests?

@aadog
Copy link
Author

aadog commented Dec 20, 2024

抱歉,刚睡醒,我现在试试,其实我们应该使用netty的pipe处理方式,他会简单很多

@aadog
Copy link
Author

aadog commented Dec 20, 2024

现在可以正常工作,不过连接后似乎会自动断开

@702455655
Copy link

抱歉,刚睡醒,我现在试试,其实我们应该使用netty的pipe处理方式,他会简单很多

How to use Socket5 proxy IP in Netty? Do you have a demo? I have tried many times in Netty but cannot interact with the server through the proxy IP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants