I am having a problem and I was curious if anyone could help me solve it.  I took a tutorial for client-server socket programming for VB.NET.  I then tried to implement it using a service rather than a program.  I understand how it works as a program, but when I try to port it over to a service it doesn't work.  When I run the service it starts and stops instantly.  It never makes a connection.  Unfortunately, I am not that great of VB.net programmer but so far I am liking it a lot for rapid development of programs.

The idea of this service is to:


run when the computer starts
grab the name of the PC
Send the name of the PC to the server

a.   the server then takes the name and looks it up in a database

b.   returns the time that the client machine is suppose to back up
The client machine then does the math for the current time and the time it’s suppose to backup &amp; put everything in ms.
Then the machine backs up at that specified time by running a dos command to launch the program.


Now to answer a question that I have found common in the forums.  Why don't I use task scheduler.  Well I did use task schedule and had the server control times to machines that way.  However, some computers will go into a dormant state, I would say this dormant state affects 20% of the machines.  No this dormant state is not sleep mode and not hibernation.  The computers are on and they are react very quickly to mouse movement.  I created a service that writes the time to a file on the C:\ and this has always worked.  So now I have decided to have a service on the client machine and have it communicate with the server.

I have collected very little information about creating service and network socket programming.  Unfortunately, I haven’t found anything that ties the 2 together.  I found a vb.net client-server program that does what I want, but I want it as a service not a program.  I found a temporary solution with creating files using PSEXEC from the server, but this process is just so umm unsophisticated.

I did the next best thing and I went and reviewed the Microsoft library for sockets and tried to build my own service based on what makes sense.  Still nothing works.  If you know of any books, resources, have any advice, etc. any help you can give me will be greatly appreciated.  Thank you for your assistance.

Below you will find my code.  At this point all I care about doing is making the connections between clients and the server.  I can go back to figuring out the rest and tweek the code from there.

Mike

Here is the server code I have been playing with:

Imports System.Net.Sockets
Imports System.Net
Imports System.Text

Public Class BackupService

    Private Mythread As Threading.Thread
    Private clientThread As Threading.Thread
    Private listener As New TcpListener(IPAddress.Parse("#.#.#.252"), 8888)



    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.

        listener.Start()            'Listener for clients
        System.IO.File.WriteAllText("C:\test\listener.txt", My.Computer.Clock.LocalTime)
        Mythread = New Threading.Thread(AddressOf listenerLoop)
        Mythread.Start()

    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Mythread.Abort()
    End Sub

    Protected Sub listenerLoop()

        Dim client As TcpClient = listener.AcceptTcpClient()
        Dim networkStream As NetworkStream = client.GetStream
        Dim bytes(client.ReceiveBufferSize) As Byte
        Dim dataReceived As String


        While True
            networkStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))            'Receives data from client and stores it into bytes
            dataReceived = Encoding.ASCII.GetString(bytes)                          'Encodes the data to ASCII standard
            System.IO.File.AppendAllText("C:\test\listener.txt", dataReceived)      'Copies information to text file
            Threading.Thread.Sleep(1000)

        End While




        'Listening for incoming connections
        'While True
        '    If (listener.Pending = False) Then
        '        System.IO.File.AppendAllText("C:\test\listener.txt", "Sorry, no connection requests have arrived")
        '    Else
        '        'Finds Incoming message and creates a thread for the client-server to pass information'
        '        clientThread = New Threading.Thread(AddressOf clientConnection)
        '        clientThread.Start()

        '    End If
        '    Threading.Thread.Sleep(1000)    'Let loop/thread sleep for 1 second to allow other processing and waits for clients
        'End While
    End Sub

    'Protected Sub clientConnection()
    '    Dim client As TcpClient = listener.AcceptTcpClient()
    '    Dim networkStream As NetworkStream = client.GetStream
    '    Dim bytes(client.ReceiveBufferSize) As Byte
    '    Dim dataReceived As String
    '    Dim datasent As Boolean = False

    '    While datasent = False  'Continuously loops looking for sent data
    '        If (networkStream.CanRead = True) Then
    '            networkStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))            'Receives data from client and stores it into bytes
    '            dataReceived = Encoding.ASCII.GetString(bytes)                          'Encodes the data to ASCII standard
    '            System.IO.File.AppendAllText("C:\test\listener.txt", dataReceived)      'Copies information to text file
    '            datasent = True
    '        End If
    '        Threading.Thread.Sleep(1000)
    '    End While

    '    networkStream.Close()       'Closes the network stream
    '    client.Close()              'Closes the client
    '    clientThread.Abort()        'Kills the the current thread

    'End Sub
End Class


Client Code (service):

Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Public Class TestWindowsService

    Dim Mythread As Threading.Thread

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.


        'clientCommunication()


        Mythread = New Threading.Thread(AddressOf KeepCounting)
        Mythread.Start()
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.

        Mythread.Abort()
    End Sub

    'Protected Sub KeepCounting()
    '    Dim wait As Integer = 0
    '    Dim hour As Integer = 0
    '    Dim min As Integer = 0

    '    System.IO.File.WriteAllText("C:\test\StartTime.txt", "Start Time: " &amp; My.Computer.Clock.LocalTime)


    '    Do While True

    '        hour = My.Computer.Clock.LocalTime.Hour

    '        If (hour = 1) Then
    '            min = (My.Computer.Clock.LocalTime.Minute * 60) + 60000
    '            Threading.Thread.Sleep(min)         'Sleeps for the number of minutes till 2am
    '            file.FileTime()
    '        Else
    '            Threading.Thread.Sleep(3600000)     'Sleeps for 1 hour
    '            System.IO.File.WriteAllText("C:\test\hourCheck\ThreadTime.txt", "Time: " &amp; My.Computer.Clock.LocalTime)

    '        End If

    '    Loop

    'End Sub

    Protected Sub KeepCounting()
        Dim tcpClient As New System.Net.Sockets.TcpClient()
        tcpClient.Connect(IPAddress.Parse("#.#.#.11"), 8000)
        Dim networkStream As NetworkStream = tcpClient.GetStream()

        If networkStream.CanWrite And networkStream.CanRead Then

            ' Do a simple write.
            Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
            networkStream.Write(sendBytes, 0, sendBytes.Length)

            ' Read the NetworkStream into a byte buffer.
            Dim bytes(tcpClient.ReceiveBufferSize) As Byte
            networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

            ' Output the data received from the host to the console.
            Dim returndata As String = Encoding.ASCII.GetString(bytes)
            Console.WriteLine(("Host returned: " + returndata))


        Else
            If Not networkStream.CanRead Then
                Console.WriteLine("cannot not write data to this stream")
                tcpClient.Close()
            Else
                If Not networkStream.CanWrite Then
                    Console.WriteLine("cannot read data from this stream")
                    tcpClient.Close()
                End If
            End If
        End If
        ' pause so user can view the console output
        Console.ReadLine()


    End Sub

End Class


Client Code (extended Module)

Imports System.Net.Sockets
Imports System.Net
Imports System.Text

Module Client_TCP_Communication

    Public Sub clientCommunication()
        Dim tcpClient As New System.Net.Sockets.TcpClient()
        tcpClient.Connect("127.0.0.1", 8000)
        Dim networkStream As NetworkStream = tcpClient.GetStream()

        If networkStream.CanWrite And networkStream.CanRead Then

            ' Do a simple write.
            Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
            networkStream.Write(sendBytes, 0, sendBytes.Length)

            ' Read the NetworkStream into a byte buffer.
            Dim bytes(tcpClient.ReceiveBufferSize) As Byte
            networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

            ' Output the data received from the host to the console.
            Dim returndata As String = Encoding.ASCII.GetString(bytes)
            Console.WriteLine(("Host returned: " + returndata))


        Else
            If Not networkStream.CanRead Then
                Console.WriteLine("cannot not write data to this stream")
                tcpClient.Close()
            Else
                If Not networkStream.CanWrite Then
                    Console.WriteLine("cannot read data from this stream")
                    tcpClient.Close()
                End If
            End If
        End If
        ' pause so user can view the console output
        Console.ReadLine()





        'Dim clientSocket As New System.Net.Sockets.TcpClient()
        'Dim serverStream As NetworkStream

        'While True
        '    serverStream = clientSocket.GetStream()
        '    Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("Message from client$")
        '    Dim inStream(1024) As Byte
        '    Dim returnData As String

        '    System.IO.File.WriteAllText("C:\test\client\ClientStarted.txt", "Time: " &amp; My.Computer.Clock.LocalTime)
        '    clientSocket.Connect(IPAddress.Parse("#.#.#.11"), 8999)
        '    System.IO.File.WriteAllText("C:\test\client\ClientConnected.txt", "Time: " &amp; My.Computer.Clock.LocalTime)

        '    serverStream.Write(outStream, 0, outStream.Length)
        '    serverStream.Flush()

        '    serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
        '    returnData = System.Text.Encoding.ASCII.GetString(inStream)
        '    System.IO.File.WriteAllText("C:\test\client\returnData.txt", "Time: " &amp; returnData)

        'End While

    End Sub

End Module



Question: What is the difference, if any, between 'art', 'the arts', and 'Art'?
Answer: Looking at etymology

art


  early 13c., "skill as a result of learning or practice," from O.Fr. art (10c.), from L. artem (nom. ars) "work of art; practical skill; a business, craft," from PIE *ar-ti- (cf. Skt. rtih "manner, mode;" Gk. arti "just," artios "complete, suitable," artizein "to prepare;" L. artus "joint;" Armenian arnam "make;" Ger. art "manner, mode"), from base *ar- "fit together, join" (see arm (1)). In M.E. usually with sense of "skill in scholarship and learning" (c.1300), especially in the seven sciences, or liberal arts. This sense remains in Bachelor of Arts, etc. Meaning "human workmanship" (as opposed to nature) is from late 14c. Sense of "cunning and trickery" first attested c.1600. Meaning "skill in creative arts" is first recorded 1610s; especially of painting, sculpture, etc., from 1660s. Broader sense of the word remains in artless.
  
  Fine arts, "those which appeal to the mind and the imagination" first recorded 1767. Expression art for art's sake (1836) translates Fr. l'art pour l'art. First record of art critic is from 1865. Arts and crafts "decorative design and handcraft" first attested in the Arts and Crafts Exhibition Society, founded in London, 1888.


Shows how the meanings evolved from a wider meaning into a more narrow one. In context of Bachelor of Arts, it is obvious that it refers to "skill in scholarship and learning". 

Today when we talk about artist and art the immediate association are paintings, sculptures and other "works to be appreciated primarily for their beauty or emotional power". 

However some connotations from older meanings still remain:


in the expression "art of making something" we don't refer to l'art pur l'art, but we refer to craftsmanship (an older meaning)   
in slightly metaphorical sense, "art of..." can be taken to mean skill, as in art of persuasion, art of motorcycle maintenance (wikipedia), art of war, rather then art that is normally exhibited in a gallery
in "college of arts and sciences", arts refer to "studies intended to provide general knowledge and intellectual skills"
in artless, the 1st meaning lists: "lacking art, knowledge, or skill", extending the semantic to include knowledge and skills in what should be a direct antonym


Also, from wikipedia on the arts


  In the Middle Ages, Artes Liberales (liberal arts) taught in medieval universities as part of the Trivium: (grammar, rhetoric, and logic) and the Quadrivium (arithmetic, geometry, music, and astronomy), and the Artes Mechanicae (mechanical arts) such as metalworking, farming, cooking, business and the making of clothes or cloth. The modern distinctions between "artistic" and non-artistic skills did not develop until the Renaissance.


I think it is reasonable to assume that such usage as in the above influenced etymologies of many other terms and I think it is easy to justify, even today, usage that when talking about arts encompasses skill and craftsmanship.

As for capitalized the Art - you will find it referring to almost anything; for more colorful examples see magic, alchemy and so on. Actually any kind of human activity can be called "art of..", and especially in the writings it is often the most appropriate word to describe studies of such interests. In those cases practitioners usually refer to their subject simply, and sometimes deliberately cryptic, as the Art.