Posts Tagged ‘Vista’

I have to let my ‘Vista’ rant out, here is my situation, my Main server is on a wireless PC running XP (Hopefully I can migrate to the main server).

But a Vista PC for some reason cannot ping or see it after some time has passed, note that it does respond as long as it its connected, but then just dies?

The only way to fix this is if I ping the vista PC from my XP client and then it works again!!?   And there are two other XP clients wireless also and they work fine!.

I’ve disabled firewalls, IPV6, Aegis and all the other stuff in my network settings…

Oh well I figure a work around somehow…. 🙂

Here’s a pic of my Trusty Icon Applicancelinc and Eagle Eye motion sensor…

Hi, in a previous article I had shown how to monitor & capture data on a specific port using VB. Mainly to allow my server send out notification to the clients, like a Caller ID Alert. That article can be found here

How to monitor and capture data in a specific port in VB / 2005

Below I’ll show the code I use on the server side to actually open and send the information to the clients.

Like mentioned above I will use the example of a caller Id alert , so the program will open a port 81 and send the text ‘callerid’ to the clients (In this case You can use PC names if you have a home router like D-link etc.

Since I have a couple of clients I use VB ‘commandline’ feature to retrieve the IP, port and message that I am going to send.  My utility is called ‘BumpClients’.  For the example lets say this how its called

“Bumpclients.exe callerid 81”

—————— Setting up the imports, make sure you include System.Net and, the others may not be needed

Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports System.Xml.XPath
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Data
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1

'------------------------------ Create the instance to of the TCP Client (Its the same as receiving)
    Public WithEvents OpenPort As TcpClient  

'------ I use the Form_load event to quickly send the message and exit the program, no user interaction is needed, we grab all paramters from the command line when called.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Minimized '- Go hidden
        Me.Hide() '- Go hidden

'------ Next using the Split command I grab the three parameters by looking for the space( This will give me the IP,the command,and port the program will use!)
'------ Data(0)=IP, Data(1)=command, Data(2)=port.

        Dim IP As String
        Dim datA_out
        Dim port As Integer

        data_out = Split(Command$(), " ")
        IP = data_out(0)
        port = data_out(2)

'------ Just a quick check to make I can ping the IP, if not just exit and dont even bother.
        If My.Computer.Network.Ping(IP) = False Then End

'---- The actualy opening of the port un a 'try' statement if it fails exit also
            OpenPort = New TcpClient(IP, port)
        End Try

'------ If all is good then go ahead and convert our text to bytes and send it out using the stream method!
       Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Trim(data_out(1)))

        Dim stream As NetworkStream = OpenPort.GetStream()
        stream.Write(data, 0, data.Length)

'------ Close and exit!- That's it!
    End Sub
End Class

A important note, remember that on your client you need to open the port you use in the firewall or it will never see anything, but you dont need to open it on the server since it will be sending.  To test this you will need the two actual computers sine you cant monitor and send data thru the same port.

In my application I actually run a external program using the system.diagnostics,process.start command, to the IP of my PC’s this way, it will run each script and not wait.And each of time will exit accordingly.


System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” ” + data_out + ” ” + port) ‘ Laptop
System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” ” + data_out + ” ” + port) ‘
System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” ” + data_out + ” ” + port) ‘


In one of my  previous post I had shown how to capture the Caller Id info of a modem.  So what do I do this the information??

In my case I notify all the PC in the house a particular caller / number is ringing by sending data on a specific port.  So they know who it is before picking up or even looking at the phone for the caller Id info. Below is the code on how to monitor a port for data.

In this case it will open and monitor port 81.  Since there is no event for the TCPListener Im using the VB timer control, then check the port for any pending data ever 1000ms , if data is pending it will read it and show it in a pop-up in the icon tray. 🙂

To keep it simple here, and Not shown here, I actually FTP back via code (Will setup another post for this) to the server and grab the image of the person which is then displayed on the client on another window.

Like all code here, is all in VB 2005. For setup: Note that for this  to work you do need to open port 81 (TCP) on the client.

Just create a basic form with the following controls (All are default names)

A Notify object called “NotifyIcon1”
A timer object called “Timer1”

‘—————— setup my Import variables, some may not be needed.

Imports System.Web
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System
Imports System.ComponentModel
Imports System.Threading
Imports Microsoft.VisualBasic

'----------------------- Here is the main class which loads the form.
Public Class Form1
    Public WithEvents OpenPort As TcpListener '--------- I setup the TCPListner object, There really isnt no events for it so I have to check using a timer.

'--------- GET THE CLIENT ip FROM THE ENVIRONMENT This will return ina array the IP of the client in the case of XP the first ip(0) should be fine, in the case
'--------- vista you have to search for it. I just looked for the first octet to be the same as my internal network.

    Public ip() As System.Net.IPAddress = System.Net.Dns.GetHostEntry(Environment.MachineName).AddressList
    Public IPAdresstxt As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'ip(0) = IPAddress.Parse(Microsoft.VisualBasic.Interaction.Command()) '---- Un-comment for XP

'------- for Vista the first item of the array can be anything, so I loop thru the values looking for the same network of my home network
        Dim ip_count As Integer
        or ip_count = 0 To ip.Length - 1
            If ip(ip_count).ToString.Contains("192") = True Then
                OpenPort = New TcpListener(ip(ip_count), 81)  '--------- Here we set the IP (My PC) and the port to monitor in this case 81
                IPAdresstxt = ip(ip_count).ToString
            End If

        OpenPort.Start() ' - Open and monitor
        NotifyIcon1.Visible = True
        NotifyIcon1.BalloonTipTitle = "Caller ID"
        NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
        NotifyIcon1.BalloonTipText = "Caller ID Running, window will close in 3 seconds"
        NotifyIcon1.ShowBalloonTip(2500)  '----------------- Hide my Icon popup after 2500 MS
        Me.Hide() '----------- This will hide my form and only leave the icon on the tray.  :)

    End Sub

'------------------ This is my main timer1 which is enabled and checked every 1 sec.
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        '-------------- CHECK PORT 81 IF GOT DATA
        If My.Computer.Network.IsAvailable = True Then  '----- If data is present then read data and pharse it.
            If OpenPort.Pending = True Then
                Dim bytes(1024) As Byte
                Dim data As String = Nothing
                Dim client As TcpClient = OpenPort.AcceptTcpClient()
                Dim stream As NetworkStream = client.GetStream()
                Dim i As Int32
                ' Loop to receive all the data sent by the client.
                i = stream.Read(bytes, 0, bytes.Length)
                While (i <> 0)
                    data = data + System.Text.Encoding.ASCII.GetString(bytes, 0, i)
                    data = data.ToUpper()
                    Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data)
                    i = stream.Read(bytes, 0, bytes.Length)
                End While

                data = LCase(data).Trim
                ShowCallerID(data)  '---------------------- Call the function to update the Notify-Icon
                Msgbox "Data received is"+data
         End If
        End If
    End Sub

'---------------------- Function to update the Notify-Icon
    Public Function ShowcallerID(number as Integer) As Boolean
        NotifyIcon1.BalloonTipText = "Incomming call from " + name + vbCrLf + " From # " + number.ToString
        IncommingCallWindow.txtName.Text = name
        If number.ToString.StartsWith("1") = True Then
            number = Val(Mid$(number, 2, number.ToString.Length - 1))
        End If

    End Function

End Class