i am writing a program that will connect to a hotmail email account a pop all of the emails to my windows form using C# but when i try and set up the enital connecting using TCPClient i get this error message
A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond 65.55.32.247:110
here is the code i am using to connect to
public TcpClient Server;
public NetworkStream NetStrm;
public StreamReader RdStrm;
Server = new TcpClient("pop3.live.com", 110);
You're using the wrong port. Use 995.
For further help working with streams to read POP3 mail, see this question.
Related
I am using System.Net.WebSockets to create a websocket client to a websocket server I am running. The following code is used to create the websocket
Debug.Log("Setting up websocket");
client = new ClientWebSocket();
await client.ConnectAsync(new Uri("ws://192.168.68.93:8001/ws"), System.Threading.CancellationToken.None);
Debug.Log($"Socket status: {client.State}");
The following error is produced:
System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
The confusing part to me, the following code in javascript works perfectly fine
const ws = new WebSocket("ws://192.168.68.93:8001/ws")
And if I log the messages I receive, they are what I expect/work perfectly fine.
What would cause a JS websocket to work, but not a C# one?
My current suspicion is the issue is actually related to the wsserver, I am running it on an esp32, using a library called ESPAsyncWebServer. But I need to know why C# would fail on it when JS works fine
Server.cs - https://hastebin.com/enajinewij.cs
Client.cs - https://hastebin.com/iriperubur.cs
I have tried both running the Client on another PC and running it on one PC, but both result in the Client not being able to receive or send any messages.
I CANT portforward. I am using Hamachi for the IP Address. Both client and server are connected to my Network and are using the Hamachi IP Address. I am using PDA Net to connect to the internet from my PC.
The Server does not see them connect at all. Nor does the Server get any messages from them. Currently only the Server can send messages, and only it can get them.
I am not getting ANY errors at all, so I am not sure how I should handle solving this issue as it's my first time working with networking.
At first you create a TcpListener and you call StartLis() that does BeginAcceptTcpClient. However in AcceptTCPClient you create a new TcpListener and BeginAcceptTcpClient is not called.
You don't have to create a new listener for each connection, but you do have to call BeginAcceptTcpclient again:
private void AcceptTCPClient(IAsyncResult ar)
{
TcpListener Lis = (TcpListener)ar.AsyncState;
Clients.Add(new ServerClient(Lis.EndAcceptTcpClient(ar)));
StartLis(); // this will call BeginAcceptTcpClient again
}
i have faced a problem about H5 websocket
this is my server code by c# , i have open a port 3030 to run socket
WebSocketServer server = new WebSocketServer("ws://127.0.0.1:3030");
then in my website,i connected to server
var ws = new WebSocket("ws://www.yummyonline.net:3030");
but,the error throwed out
WebSocket connection to 'ws://www.yummyonline.net:3030/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
while i define like this in my website
var ws = new WebSocket("ws://127.0.0.1:3030");
it will work.
could anyone can teach me why ?
You tell your server to listen only on 127.0.0.1, therefore it will not be accepting connections on any other address or interface.
Try using WS://0.0.0.0:3030 as the binding to listen on all interfaces and addresses.
I wrote a simple tcp/ip chat and it worked with the localhost IP(127.0.0.1) as well as connecting to another computer on the local network.
Through the Internet (v4 IP address) it didn't work so I tried the codeproject example:
I downloaded but it threw the same exception on connecting:
TcpClient Client = New TcpClient(IPAddr, 65535);
I tried with another port and turned off Windows-Firewall and Avira-Free.
Update:
If I connect to another Internet IP address, the following exception is thrown:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond IP-Address: 65535
Probably this won't help, but perhaps try another port?
I'm trying to make something that will read email, but I can't get anything to work. This code:
TcpClient c = new TcpClient();
c.Connect("imap.gmail.com", 993);
NetworkStream stream = c.GetStream();
stream.ReadTimeout = 1000;
stream.ReadByte();
Seams to be where any code I download breaks. The last line throws an IOException with the message: "Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."
I would settle for a third party program that automatically downloads email in a format I can read. I have gotten Thunderbird to connect to gmail so the problem is on my end for sure.
You are connecting on the SSL port. If you do not do a proper SSL-handshake, it will close the connection shortly after without sending you any data.
The message indicates that the remote server did not respond. It did not say "no connection allowed on this port". It did not say "I close the connection". It said nothing.
This means that you are not able to even create a connection on the TCP level. Try this:
telnet imap.gmail.com 993
It will fail. So it has nothing to do with you application.
use openssl to connect to gmail. its an easy way to get your things done.
Gmail IMAP uses SSL, so you need to wrap your network stream with SslStream and call AuthenticateAsClient method (so that it does the SSL handshake/server authentication magic). After that you interact with it as if it's normal (non-SSL) stream:
TcpClient c = new TcpClient();
c.Connect("imap.gmail.com", 993);
SslStream sslStream = new SslStream(c.GetStream());
sslStream.ReadTimeout = 1000;
sslStream.AuthenticateAsClient("imap.gmail.com");
sslStream.ReadByte();