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

C#

 
AnswerRe: Reading values from window-form to XNA Pin
Ron Beyer5-Jan-14 17:52
professionalRon Beyer5-Jan-14 17:52 
GeneralRe: Reading values from window-form to XNA Pin
larsp7775-Jan-14 22:09
larsp7775-Jan-14 22:09 
GeneralRe: Reading values from window-form to XNA Pin
Ron Beyer6-Jan-14 7:44
professionalRon Beyer6-Jan-14 7:44 
GeneralRe: Reading values from window-form to XNA Pin
larsp7776-Jan-14 8:24
larsp7776-Jan-14 8:24 
GeneralRe: Reading values from window-form to XNA Pin
larsp7773-Feb-14 22:00
larsp7773-Feb-14 22:00 
Questionhow i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
h.k_net4-Jan-14 21:32
h.k_net4-Jan-14 21:32 
AnswerRe: how i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
Kornfeld Eliyahu Peter4-Jan-14 22:29
professionalKornfeld Eliyahu Peter4-Jan-14 22:29 
QuestionCreating C# TCP listener windows Service Pin
Tobben_4-Jan-14 11:47
Tobben_4-Jan-14 11:47 
Hi I am trying to create a TCP Socket Listener that installes as a windows service. I have created a console applications that works file, see code. But after reading pages and pages on how to create a window service I am stuck. It is how to handle start and stop of the service that is my biggest problem. Does any one have any ideas/tips?

Regards
Tobben

public class SynchronousSocketListener
{

    // Incoming data from the client.
    public static string data = null;

    public static void StartListening()
    {
        // Data buffer for incoming data.
        byte[] bytes = new Byte[1024];


        // Establish the local endpoint for the socket.
        // Dns.GetHostName returns the name of the 
        // host running the application.
        IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
        IPAddress ipAddress = ipHostInfo.AddressList[0];
        IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);


        // Create a TCP/IP socket.
        Socket listener = new Socket(AddressFamily.InterNetwork,
            SocketType.Stream, ProtocolType.Tcp);

        // Bind the socket to the local endpoint and 
        // listen for incoming connections.
        try
        {
            listener.Bind(localEndPoint);
            listener.Listen(10);

            // Start listening for connections.
            while (true)
            {
                Console.WriteLine("Waiting for a connection...");
                // Program is suspended while waiting for an incoming connection.
                Socket handler = listener.Accept();
                data = null;

                // An incoming connection needs to be processed.
                while (true)
                {
                    bytes = new byte[1024];
                    int bytesRec = handler.Receive(bytes);
                    data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                    if (data.IndexOf("=)") > -1) //if =) comes in, start notepad.exe
                    {
                        //Insert action after Client is Connected
                        System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe");
                        break;
                    }
                    if (data.IndexOf("=(") > -1) //if =( comes in, start notepad.exe
                    {
                        //Insert action after Client is Connected
                        System.Diagnostics.Process.Start(@"C:\Windows\System32\cmd.exe");
                        break;
                    }
                   
                }

                // Show the data on the console.
                Console.WriteLine("Text received : {0}", data);

                // Echo the data back to the client.
                byte[] msg = Encoding.ASCII.GetBytes(data);

                handler.Send(msg);
                handler.Shutdown(SocketShutdown.Both);
                handler.Close();
            }

        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

        Console.WriteLine("\nPress ENTER to continue...");
        Console.Read();

    }

    public static int Main(String[] args)
    {
        StartListening();
        return 0;
    }
}

AnswerRe: Creating C# TCP listener windows Service PinPopular
Ron Beyer4-Jan-14 12:00
professionalRon Beyer4-Jan-14 12:00 
QuestionGetting Thread Exception: while using System.Timer Class Pin
Member 99612394-Jan-14 7:16
Member 99612394-Jan-14 7:16 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Pete O'Hanlon4-Jan-14 8:15
mvePete O'Hanlon4-Jan-14 8:15 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Dave Kreskowiak4-Jan-14 10:20
mveDave Kreskowiak4-Jan-14 10:20 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Brite Varghese9-Jan-14 6:22
Brite Varghese9-Jan-14 6:22 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Member 99612399-Jan-14 17:47
Member 99612399-Jan-14 17:47 
QuestionC# datagridview navigator Pin
Member 78188924-Jan-14 3:58
Member 78188924-Jan-14 3:58 
AnswerRe: C# datagridview navigator Pin
Alan N4-Jan-14 4:20
Alan N4-Jan-14 4:20 
Questionabout Sign unsigned drivers Pin
delphix53-Jan-14 8:43
delphix53-Jan-14 8:43 
AnswerRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 9:05
mveDave Kreskowiak3-Jan-14 9:05 
GeneralRe: about Sign unsigned drivers Pin
delphix53-Jan-14 9:37
delphix53-Jan-14 9:37 
GeneralRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 10:29
mveDave Kreskowiak3-Jan-14 10:29 
GeneralRe: about Sign unsigned drivers Pin
delphix53-Jan-14 10:50
delphix53-Jan-14 10:50 
GeneralRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 14:11
mveDave Kreskowiak3-Jan-14 14:11 
GeneralRe: about Sign unsigned drivers Pin
delphix54-Jan-14 2:48
delphix54-Jan-14 2:48 
Questionget the property name of custom folder Pin
Member 102635192-Jan-14 19:54
Member 102635192-Jan-14 19:54 
AnswerRe: get the property name of custom folder Pin
Eddy Vluggen3-Jan-14 6:23
professionalEddy Vluggen3-Jan-14 6:23 

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.