an existing connection was forcibly closed by the remote host
This happens with a socket connection between client and server. The connection is alive and well, and heaps of data is being transferred, but it then becomes disconnected out of nowhere.
Latest....
Server Program
===============
class Program
{
public static void StartServer()
{
byte[] bytes = new byte[1024];
try
{
try
{
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = new IPAddress(new byte[] { 192, 168, 1, 105 });
//ipadd = ds.Tables[0].Rows[i]["IP"].ToString();
//IPAddress ipAddress = new IPAddress(Encoding.ASCII.GetBytes(ipadd ));
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);
Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sender.Connect(remoteEP);
Console.WriteLine("Socket connected to {0}",
sender.RemoteEndPoint.ToString());
byte[] msg = Encoding.ASCII.GetBytes("date");
int bytesSent = sender.Send(msg);
int bytesRec = sender.Receive(bytes);
Console.WriteLine("Echoed test {0}= {1}", ipAddress.ToString(),
Encoding.ASCII.GetString(bytes, 0, bytesRec));
}
catch (ArgumentNullException ane)
{
Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
}
catch (SocketException se)
{
Console.WriteLine("SocketException : {0}", se.ToString());
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
}
//}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
static void Main(string[] args)
{
StartServer();
Console.Read();
}
Client Program
==============
class Program
{
public static string data = null;
public static void StartListening()
{
byte[] bytes = new Byte[1024];
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
while (true)
{
Console.WriteLine("Waiting for a connection...");
Socket handler = listener.Accept();
data = null;
while (true)
{
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
break;
}
if (data == "date")
{
System.Diagnostics.Process process1;
process1 = new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
*******************************
System.Diagnostics.Process.Start("Notepad.exe");//, strCmdLine);
*******************************
process1.Close();
byte[] msg = Encoding.ASCII.GetBytes("operation completed");
handler.Send(msg);
}
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
static void Main(string[] args)
{
StartListening();
}
This Program Execute without error...
i change the code notepad.exe to visualstudio setupproject.exe that returns network socket exception