Hello everyone
I set up a program to send a message of "DISCONNECTCAMERA" to a certain IP address.
When it receives the message, it disconnects its webcam.
(i'm making a program like skype, and my friend's ip's are in My.settings)
The problem is that when i connect to an ip address that is unresponsive, i have to wait ages for the timeout to be reached.
Can you change the timeout so you dont have to wait to find out that it's unresponsive?
I tried My.Computer.Network.Ping(ipaddress, timeout) but that didn't work
My code:
Imports System.Net.Sockets
Imports System.IO
Public Class DisconnectAllCameras
Dim Receiver As New TcpListener(65535)
Dim Snder As New TcpClient
Private Sub DisconnectAllCameras_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Receiver.Stop()
Snder.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Computer.Network.Ping(My.Settings.Camera1IP)
Receiver.Start()
SendMessage(My.Settings.IP, "DISCONNECTCAMERA")
End If
End Sub
Function SendMessage(ByVal IP As String, ByVal Message As String)
Snder = New TcpClient(IP, 65535)
Dim Writer As New StreamWriter(Snder.GetStream())
Writer.Write(Message)
Writer.Flush()
If My.Settings.Camera1IP = IP Then
Label1.Text = "Camera 1 : Offline"
PictureBox1.Image = My.Resources.tick
End If
If My.Settings.Camera2IP = IP Then
Label2.Text = "Camera 2 : Offline"
PictureBox2.Image = My.Resources.tick
End If
If My.Settings.Camera3IP = IP Then
Label3.Text = "Camera 3 : Offline"
PictureBox3.Image = My.Resources.tick
End If
If My.Settings.Camera4IP = IP Then
Label4.Text = "Camera 4 : Offline"
PictureBox4.Image = My.Resources.tick
End If
End Function
Private Sub MessageReceiver_Tick() Handles MessageReceiver.Tick
If Receiver.Pending = True Then
Snder = Receiver.AcceptTcpClient()
Dim Reader As New StreamReader(Snder.GetStream())
Dim Message As String = ""
While Reader.Peek > -1
Message &= Convert.ToChar(Reader.Read()).ToString
End While
MsgBox(Message)
End If
End Sub
End Class