Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:

VB
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
Posted
Updated 13-Apr-13 6:19am
v2

1 solution

Of course, the client cannot modify the server-side timeout. Don't you think that if some service allowed such things, it would be no good? What would you say about its security than. But you can disconnect or stop connecting on client side. Of course, it's good to have all the client communication is a separate thread.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900