My system is accessing internet via a proxy server
(IE proxy server address : myserver.mydomain.com , port: 80).
Im trying to send some data to a TCP server using class "System.Net.Sockets.TcpClient". But i am unable to connect. If I try using static IP internet, i am able to connect.
Is there any way to provide proxy address ? I am pretty sure the problem is the proxy, because i have tried from two systems which do not use proxy and it worked fine.
My application is a console application.
My Code is something like :
TcpClient tcpClient = new TcpClient("tcpserver.com", 3101);
string message = "message";
byte[] auditMessageStream;
auditMessageStream = Encoding.UTF8.GetBytes(message);
int i = tcpClient.Client.Send(auditMessageStream);
You can use this opensource lib to create a socket conection through a proxy.
Watch this too
You need HTTP tunneling unless your proxy is a SOCKS proxy.
Related
I have a server and a client app, the server throws no exception and seems to listen properly but the clients aren't able to connect for some reasons, I tried with both local network and public IP.
-With local network's IP I can connect to it only when the client app is runned on the same computer than the server.
-With public IP nothing can connect to the server.
However in both cases when the connection fails, it behaves always the same : waits for aproximately 5-10 seconds and then throws System.Net.Socket.SocketException. I tried with port 1507 first then tried with port 80 but it didn't change anything
Server
IPAddress adress = IPAddress.Parse(MyIp);
TcpListener listener = new TcpListener(adress, 80);
listener.Start();
TcpClient Client = await listener.AcceptTcpClientAsync();
Client
TcpClient client = new TcpClient();
client.ConnectAsync(IPAddress.Parse(MyIp), 80).GetAwaiter().GetResult();
I don't understand where the problem comes from, is it coming from my code or not? If not the what could it be and how could I fix it?
Have you tried Telnet from outside network on specific port?
If you can't connect probably is router port redirection or access is blocked by firewall.
I'm developing an application in ASP.NET using Visual Basic, that have to connect to a Server in my private network.
The application must working only into my network (in future it can work on internet, too),
now I have a problem with TcpClient on ASP.NET: If I connect to the Server using an instance of IPAddress
Client = New TcpClient
Client.Connect(New IPAddress("192.168.1.12"), 6001)
the Socket try to connect to 176.64.116.11 (that's not my public IP Address...), else, if I connect to the server with a string that contains the local IP Address
Client = New TcpClient
Client.Connect("192.168.1.12", 6001)
the Socket connects succesfully but nothing responds to my command (with NetworkStream.Write and Read)
I try all of these in a Windows Application and all work succesfully.
Thanks to all
(I made any mistake in English? Ahaha, sorry :D)
PS. If you post me some code in C# don't worry, I can translate it
TcpClient has various overloads, you can give it a string containing the ip address or an IPAddress object.
Also, use
IPAddress ipAddress = IPAddress.Parse("192.168.1.12");
IPAddress does not contain a constructor that takes a string.
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.connect.aspx
As for your transmission issue; disable firewalls. Try localhost first.
I am using a library called Lidgren network that handles all the network part of my application. It uses UDP.
I never had any problem with TCP applications and port forwarding (apache, FTP, SMTP, etc). I did some TCP applications using TCP and I could connect without a problem.
I am making an online game right now and I use UDP for network transmission. I port forwarded it in my router and I have it running. When I use my remote IP Address (190.136.243.40) to connect to it, I can't. When I use loopback (127.0.0.1) I can connect without any kind of problem.
I turned off Windows firewall, I rebooted the computer, but I still can't connect using my remote IP Address.
Here is part of my code:
public static class ServerInfo
{
static ServerInfo()
{
ServerAddress = Dns.GetHostAddresses("leboran.dyndns.org")[0];
}
public const short Port = 6483;
public static IPAddress ServerAddress;
public const string AppIdentifier = "UnnamedGameNet";
public static byte[] MagicByte
{
get
{
return new byte[4] { 0xF1, 0x64, 0x83, 0xC4 };
}
}
}
This is the part where I start my server, probably not important:
public void StartServer()
{
this.listenThread = new Thread(ListenForClients);
peerConfig = new NetPeerConfiguration(SharedConstants.ServerInfo.AppIdentifier);
peerConfig.Port = SharedConstants.ServerInfo.Port;
peerConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
peerConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
peerConfig.ConnectionTimeout = 2144124;
netServer = new NetServer(peerConfig);
listenThread.Start();
}
The port I am using is 6483. I am running a Minecraft server at port 25565 and it works perfectly, so it is not a bad configuration on the router
Some computers have multiple ips in fact they all do, what you are probably experiencing is you've bound you app to listen to port 127.0.0.1 rather than 64.323.23.234 or ideally 0.0.0.0 which would bind all your ips. Check to see if peerConfig lets you pick what ip you are binding to the default may be 127.0.0.1
Also could be a problem with a Router. Try making your computer the DMZ or enabling port forwarding.
I dont think this is code related.
Your router would need to have the host configured because you are trying to connect directly to the public end of your router from the private side of it.
If you just want to be able to connect to the dyndns address so you dont have to change code you can also alter the windows hosts file.
Many consumer routers use the source of a packet to determine whether to treat the data as internal or external. Put another way, if you are on your internal network and try to access any of the IP addresses of your router, your router will treat it as being internal (i.e. responding to port 80 with a customization website, most others with no response).
Unfortunately solutions are hard to come by.
I made a program that connects to a server (which I also wrote) via TCP\IP.
When testing on the same computer - it works fine (connect to 127.0.0.1), but it doesn't work on different computers.
I have an NOIP address also - how can I use it?
I did try using my address itself (80.whatever) on both the client and server and it didn't connect at all - it couldn't reach the host.
What should I do?
Try disabling your windows Firewall.
Make sure your server is binding to all of your IP addresses, not just localhost (127.0.0.1).
Oh - basically I found out that I don't need to supply my IP address - I just did:
_client = new TcpListener(1234);
I am trying to create a simple xmpp client that connects to Gtalk.
The first part of the handshake seems to work.
Ror the TLS handshake I created a client SslStream, connected to the intended server (talk.google.com) and successfully got authenticated .
The first SSlStream.Read is to receive the greeting reply, it went fine . I do a SslStream.write to send my first command, but when i do my Sslstream.Read() to get the reply , i get this error."System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."
Can anyone point me to the right direction?
I am using code very similar to the example on msdn http://msdn.microsoft.com/en-us/library/system.net.security.sslstream.aspx
except that I switch from a Network stream to a Sslstream when TLS is negotiated.
netStream.Flush();
sslStream = new SslStream(netStream,
true,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
sslStream.AuthenticateAsClient("talk.google.com");
I'd try using one of the existing XMPP libraries for .Net:
Jabber-Net: http://code.google.com/p/jabber-net/
agsXMPP: http://www.ag-software.de/agsxmpp-sdk/
Even if you don't use of these libs, you'll get some good ideas from looking at the code.
In this case, you probably want:
sslStream.AuthenticateAsClient("gmail.com");
where gmail.com is the domain name from the JID you're trying to log in as.