Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
QuestionDeserialize XML in .NET 2.0 Pin
Member 1171394227-Jun-15 10:07
Member 1171394227-Jun-15 10:07 
AnswerRe: Deserialize XML in .NET 2.0 Pin
Afzaal Ahmad Zeeshan27-Jun-15 10:29
professionalAfzaal Ahmad Zeeshan27-Jun-15 10:29 
QuestionHow Print using dot metric in Web as well as Desktop in C# Pin
Saneesh kunjunni27-Jun-15 5:36
Saneesh kunjunni27-Jun-15 5:36 
AnswerRe: How Print using dot metric in Web as well as Desktop in C# Pin
Sascha Lefèvre27-Jun-15 5:45
professionalSascha Lefèvre27-Jun-15 5:45 
GeneralRe: How Print using dot metric in Web as well as Desktop in C# Pin
Saneesh kunjunni27-Jun-15 6:41
Saneesh kunjunni27-Jun-15 6:41 
GeneralRe: How Print using dot metric in Web as well as Desktop in C# Pin
Sascha Lefèvre27-Jun-15 7:04
professionalSascha Lefèvre27-Jun-15 7:04 
GeneralRe: How Print using dot metric in Web as well as Desktop in C# Pin
Richard MacCutchan27-Jun-15 7:07
mveRichard MacCutchan27-Jun-15 7:07 
QuestionSend and Receive Encoding.Unicode text via sockets, Split it and compare the string Pin
surfersockets27-Jun-15 2:09
surfersockets27-Jun-15 2:09 
I'm trying to send Unicode, so i changed my client and server Send and Receive methods in this way:

for the Server:

C#
public string Receive(Socket client)
{
    int len;
    byte[] data = new byte[1024];
    StringBuilder sb = new StringBuilder();
    while ((len = client.Receive(data)) == data.Length)
    {
        sb.Append(Encoding.Unicode.GetString(data).Substring(0, len));
    }
    sb.Append(Encoding.Unicode.GetString(data).Substring(0, len));
 
    return sb.ToString();
}
 
public void Send(Socket client, string prompt)
{
    client.Send(Encoding.Unicode.GetBytes(prompt));
}


for the Client

C#
public string Receive()
{
    int len;
    byte[] data = new byte[1024];
    StringBuilder sb = new StringBuilder();
    while ((len = client.Receive(data)) == data.Length)
    {
        sb.Append(Encoding.Unicode.GetString(data).Substring(0, len));
    }
    sb.Append(Encoding.Unicode.GetString(data).Substring(0, len));
 
    return sb.ToString();
}
 
public void Send(string prompt)
{
    client.Send(Encoding.Unicode.GetBytes(prompt));
}


As you can see, both programs have the same Send and Receive methods with the only difference that the methods of the server has a parameter in more (Socket client), just because the server starts a different tread for each one client who ask for connection, in the way to permise to the server to accepts connection by different clients at the same time ( however, I think this has nothing to do with my issue ).

I just want to point out that everything works properly if instead of use Encoding.Unicode i use Encoding.ASCII

Now in my server program i switch the received command in this way:

C#
string command = myServer.Receive(client); // Unicode  

// Console.WriteLine(command);  

string[] cmd = command.Split(' ');    
 
if (cmd.Length == 1)  
{  
 
    if (cmd[0] == "cd")  
 
    {  
        message = myServer.CurrentPath;  
 
        myServer.Send(client, message);  
    }    
 
    // here others "else if" united by the property (cmd.Length == 1)  

  
    else 
    {  
        message = "Command not found";  
   
 
        myServer.Send(client, message);  
    }
}  


but happens that when i send the command from the client to the server i retrieve back from the server the message:

"Command not found"

What and where is my error and how can I solve it?

I'm not a great programmer and if by chance I guessed a few lines of code do not be fooled, it's just because I'm working on this program for a long time. So if you want give more than good advice and you want help me with a few lines of code do not feel restrained by the fear of offending me, on the contrary I will appreciate it very much.

Thanks to all who help me.
SuggestionRe: Send and Receive Encoding.Unicode text via sockets, Split it and compare the string Pin
Richard MacCutchan27-Jun-15 2:43
mveRichard MacCutchan27-Jun-15 2:43 
QuestionGenerics & XML Pin
Member 1171394227-Jun-15 0:57
Member 1171394227-Jun-15 0:57 
AnswerRe: Generics & XML Pin
F-ES Sitecore27-Jun-15 2:33
professionalF-ES Sitecore27-Jun-15 2:33 
QuestionIs it possible to use javascript mediastream in C#? Pin
Member 1161266226-Jun-15 16:22
Member 1161266226-Jun-15 16:22 
QuestionMessage Closed Pin
26-Jun-15 16:09
Member 1085088626-Jun-15 16:09 
AnswerRe: build keylogger Pin
Dave Kreskowiak26-Jun-15 17:33
mveDave Kreskowiak26-Jun-15 17:33 
RantVisual Studio Express 2013 Installer Package Pin
Member 932620926-Jun-15 15:10
Member 932620926-Jun-15 15:10 
GeneralRe: Visual Studio Express 2013 Installer Package Pin
Gerry Schmitz26-Jun-15 16:43
mveGerry Schmitz26-Jun-15 16:43 
QuestionXmlWriter WriteString Color Pin
haithomy25-Jun-15 7:37
haithomy25-Jun-15 7:37 
AnswerRe: XmlWriter WriteString Color Pin
Dave Kreskowiak25-Jun-15 10:22
mveDave Kreskowiak25-Jun-15 10:22 
QuestionC# code is only inserting a few records. Pin
Norris Chappell25-Jun-15 7:15
Norris Chappell25-Jun-15 7:15 
AnswerRe: C# code is only inserting 1 record. Pin
F-ES Sitecore25-Jun-15 7:23
professionalF-ES Sitecore25-Jun-15 7:23 
AnswerRe: C# code is only inserting 1 record. Pin
Dave Kreskowiak25-Jun-15 7:31
mveDave Kreskowiak25-Jun-15 7:31 
GeneralRe: C# code is only inserting 1 record. Pin
Norris Chappell25-Jun-15 9:12
Norris Chappell25-Jun-15 9:12 
GeneralRe: C# code is only inserting 1 record. Pin
Dave Kreskowiak25-Jun-15 10:20
mveDave Kreskowiak25-Jun-15 10:20 
GeneralRe: C# code is only inserting 1 record. Pin
Norris Chappell25-Jun-15 13:05
Norris Chappell25-Jun-15 13:05 
GeneralRe: C# code is only inserting 1 record. Pin
Sascha Lefèvre25-Jun-15 14:25
professionalSascha Lefèvre25-Jun-15 14:25 

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.