HI,
I am very new to C# socket. I have tried several very simple code, but all of them lead to same error message:
System.Net.Sockets.SocketException: No connection could be made because the target
machine actively refused it 127.0.0.1:7
at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at MainClass.Main(String[] args) in C:\ConsoleApplication1\Program.cs:line 14
Below is one of the example code.
I searched though the net, but could not figure out it. :(
I have turned the firewall off. The code is running on win7.
Can someone point me the way out. As this is my first time programming for socket, please give more detail if possible. Thanks a lot.
using System;
using System.IO;
using System.Net.Sockets;
class MainClass
{
const int echoPort = 7;
[STAThread]
static void Main(string[] args)
{
using ( TcpClient tc = new TcpClient( "localhost", echoPort ) ) // <-- get exception here
{
NetworkStream ns = tc.GetStream();
StreamWriter sw = new StreamWriter( ns );
StreamReader sr = new StreamReader( ns );
sw.WriteLine( "test message" );
sw.Flush();
System.Console.WriteLine( sr.ReadLine() );
}
}
}