Click here to Skip to main content
15,891,657 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to store a large number of XML to the MSSQL200 database in a field Pin
Christian Graus1-Jun-09 19:38
protectorChristian Graus1-Jun-09 19:38 
Questionis it bug of the microsoft?(about multilanguage) [modified] Pin
yuwenxiang1-Jun-09 14:59
yuwenxiang1-Jun-09 14:59 
QuestionC# TCP Close Socket Question Pin
Serpendiem1-Jun-09 13:43
Serpendiem1-Jun-09 13:43 
AnswerRe: C# TCP Close Socket Question Pin
Luc Pattyn1-Jun-09 14:41
sitebuilderLuc Pattyn1-Jun-09 14:41 
Question[Message Deleted] Pin
Star091-Jun-09 13:08
Star091-Jun-09 13:08 
AnswerRe: Can't Add a Row ( Access DB) Pin
Christian Graus1-Jun-09 13:10
protectorChristian Graus1-Jun-09 13:10 
AnswerRe: [Message Deleted] Pin
Colin Angus Mackay1-Jun-09 13:21
Colin Angus Mackay1-Jun-09 13:21 
QuestionC# TCP Cycle Pin
Serpendiem1-Jun-09 12:42
Serpendiem1-Jun-09 12:42 
My current code works fine, but I've encountered a problem. When a client connects to the TCP server, and they type a message it works the first time, but if its entered again, it just gives you the else. So lets say I typed shutdown in the client console. It would return Command Recieved, Initiating Shutdown. But if I try it again, it just gives me the else message. Its like its not cycling through the if statement again. What kind of code should I use to solve this issue?

Here is the code:

/*

C# TCP
by Joshua Garrett

 */


using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class Server
{
    public static void Main()
    {
        byte[] data = new byte[1024];
        IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7557);
        UdpClient newsock = new UdpClient(ipep);

        Console.WriteLine("Waiting for a client...");

        IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

        data = newsock.Receive(ref sender);

        Console.WriteLine("Connection received from {0}", sender.ToString());

        string welcome = "OpticVPS Remote Administration";  //where?
        data = Encoding.ASCII.GetBytes(welcome);
        newsock.Send(data, data.Length, sender);

        while (true)
        {
            data = newsock.Receive(ref sender);

                
            if (Encoding.ASCII.GetString(data, 0, data.Length) == "help")
            {
                string okay = "You can use the following commands";

                Console.WriteLine("Help List Accessed By: {0}", sender.ToString());
                
                data = Encoding.ASCII.GetBytes(okay);
                newsock.Send(data, data.Length, sender);
            }
            else if (Encoding.ASCII.GetString(data, 0, data.Length) == "shutdown")
            {
                string shutdown = "Command Received, Shutting Down Now";

                Console.WriteLine("Shutdown Issued - {0}", sender.ToString());

                data = Encoding.ASCII.GetBytes(shutdown);
                newsock.Send(data, data.Length, sender);


            }
            else
            {
                string err = "Command Not Found [End Of Line]";

                Console.WriteLine("Command Error - {0}", sender.ToString());

                data = Encoding.ASCII.GetBytes(err);
                newsock.Send(data, data.Length, sender);
            
            }
           // newsock.Send(data, data.Length, sender);
        }
    }
    
}


[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#

AnswerRe: C# TCP Cycle Pin
Jimmanuel1-Jun-09 14:42
Jimmanuel1-Jun-09 14:42 
Questionpda(push down automata) Pin
chavir1-Jun-09 12:00
chavir1-Jun-09 12:00 
AnswerRe: pda(push down automata) Pin
Christian Graus1-Jun-09 12:22
protectorChristian Graus1-Jun-09 12:22 
Questionpda automata Pin
chavir1-Jun-09 11:57
chavir1-Jun-09 11:57 
AnswerRe: pda automata Pin
Pete O'Hanlon1-Jun-09 12:07
mvePete O'Hanlon1-Jun-09 12:07 
GeneralRe: pda automata Pin
chavir1-Jun-09 12:54
chavir1-Jun-09 12:54 
GeneralRe: pda automata Pin
Christian Graus1-Jun-09 12:59
protectorChristian Graus1-Jun-09 12:59 
GeneralRe: pda automata Pin
Pete O'Hanlon1-Jun-09 21:42
mvePete O'Hanlon1-Jun-09 21:42 
GeneralRe: pda automata Pin
Panorama1416-Jan-10 22:11
Panorama1416-Jan-10 22:11 
AnswerRe: pda automata Pin
Christian Graus1-Jun-09 12:23
protectorChristian Graus1-Jun-09 12:23 
QuestionCreating a Panel from with in a class Pin
Gary Strunk1-Jun-09 11:51
Gary Strunk1-Jun-09 11:51 
AnswerRe: Creating a Panel from with in a class Pin
Luc Pattyn1-Jun-09 12:19
sitebuilderLuc Pattyn1-Jun-09 12:19 
AnswerRe: Creating a Panel from with in a class Pin
Satish Pai1-Jun-09 18:19
Satish Pai1-Jun-09 18:19 
QuestionDrop Down List Issue Pin
sebogawa1-Jun-09 11:47
sebogawa1-Jun-09 11:47 
AnswerRe: Drop Down List Issue Pin
Christian Graus1-Jun-09 12:24
protectorChristian Graus1-Jun-09 12:24 
QuestionMessage Removed Pin
1-Jun-09 11:29
professionalN_tro_P1-Jun-09 11:29 
AnswerRe: Active Directory Issues Pin
Luc Pattyn1-Jun-09 11:34
sitebuilderLuc Pattyn1-Jun-09 11:34 

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.