Click here to Skip to main content
15,915,676 members
Home / Discussions / C#
   

C#

 
GeneralRe: Rich Text Box Flicker Pin
Paul Unsworth5-May-09 21:15
Paul Unsworth5-May-09 21:15 
QuestionCalling C# function in Java Pin
raesa5-May-09 1:40
raesa5-May-09 1:40 
AnswerRe: Calling C# function in Java Pin
Nagy Vilmos5-May-09 1:54
professionalNagy Vilmos5-May-09 1:54 
GeneralRe: Calling C# function in Java Pin
raesa5-May-09 2:02
raesa5-May-09 2:02 
GeneralRe: Calling C# function in Java Pin
Tom Deketelaere5-May-09 2:25
professionalTom Deketelaere5-May-09 2:25 
GeneralRe: Calling C# function in Java Pin
Nagy Vilmos5-May-09 2:29
professionalNagy Vilmos5-May-09 2:29 
QuestionProcess's changes Pin
lost_in_code5-May-09 1:09
lost_in_code5-May-09 1:09 
Questionc# socket server error Pin
Whydah5-May-09 0:49
Whydah5-May-09 0:49 
Hi,

I have this problem with C# socket server that's talking to a perl client. When I run the server and run the perl client with "perl client.pl commandtoexecute" the server executes the command displaying it on the server console and then crashes with this error:

Unhandled Exception: System.IO.IOException: Unable to read data from the transpo
rt connection: An existing connection was forcibly closed by the remote host. --
-> System.Net.Sockets.SocketException: An existing connection was forcibly close
d by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
--- End of inner exception stack trace ---

I know I am not handling the error correctly, but I have no idea how do I go about fixing this. Any ideas? here is the code for the method that is handling the client connections:

public void HandleConnection()
{
int recv;
byte[] data = new byte[2048000];

TcpClient client = threadListener.AcceptTcpClient();
NetworkStream ns = client.GetStream();
connections++;
Console.WriteLine("New client accepted: {0} active connections", connections);
string welcome = "Welcome to power shell server ... ";
data = Encoding.ASCII.GetBytes(welcome);
ns.Write(data, 0, data.Length);
while (true)
{
data = new byte[2048000];
recv = ns.Read(data, 0, data.Length);
if (recv == 0)
break;
else
{
String cmd = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine(cmd);
//Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
//ns.Write(Encoding.UTF8.GetBytes(RunShell(cmd)), Convert.ToString((RunShell(cmd))).Length, 10000000);

// Execute incoming shell command and convert the string data to byte data using ASCII encoding.
byte[] byteData = Encoding.ASCII.GetBytes(RunShell(cmd));

// Begin sending the data to the remote device.
if (byteData.Length > 0)
ns.Write(byteData, 0, byteData.Length);
else
{
Console.Write("\nData Length is less than 0");
ns.Write(data, 0, recv);
}
}
}
ns.Close();
client.Close();
connections--;
Console.WriteLine("Client disconnected: {0} active connections", connections);
}
AnswerRe: c# socket server error Pin
stancrm5-May-09 2:09
stancrm5-May-09 2:09 
GeneralRe: c# socket server error Pin
Whydah5-May-09 3:20
Whydah5-May-09 3:20 
QuestionConvert string to Font Pin
yesu prakash5-May-09 0:48
yesu prakash5-May-09 0:48 
AnswerRe: Convert string to Font Pin
Michael Bookatz5-May-09 1:02
Michael Bookatz5-May-09 1:02 
AnswerRe: Convert string to Font Pin
Baran M5-May-09 3:44
Baran M5-May-09 3:44 
AnswerRe: Convert string to Font Pin
khodadadeh1-Sep-10 14:13
khodadadeh1-Sep-10 14:13 
QuestionFilename check with extention Pin
Yogesh Tayade5-May-09 0:28
Yogesh Tayade5-May-09 0:28 
AnswerRe: Filename check with extention Pin
Malmberg5-May-09 0:33
Malmberg5-May-09 0:33 
QuestionDelete line from Excel file Pin
polycom1234-May-09 23:00
polycom1234-May-09 23:00 
AnswerRe: Delete line from Excel file Pin
Christian Graus4-May-09 23:05
protectorChristian Graus4-May-09 23:05 
GeneralRe: Delete line from Excel file Pin
OriginalGriff4-May-09 23:34
mveOriginalGriff4-May-09 23:34 
GeneralRe: Delete line from Excel file Pin
polycom1235-May-09 0:15
polycom1235-May-09 0:15 
GeneralRe: Delete line from Excel file Pin
polycom1235-May-09 0:11
polycom1235-May-09 0:11 
AnswerRe: Delete line from Excel file Pin
Philipp Sumi4-May-09 23:32
Philipp Sumi4-May-09 23:32 
AnswerThe solution Pin
polycom1235-May-09 2:11
polycom1235-May-09 2:11 
GeneralRe: The solution Pin
dan!sh 5-May-09 2:44
professional dan!sh 5-May-09 2:44 
GeneralRe: The solution Pin
Dave Kreskowiak5-May-09 4:43
mveDave Kreskowiak5-May-09 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.