Click here to Skip to main content
13,055,083 members (54,588 online)
Rate this:
Please Sign up or sign in to vote.
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:

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
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        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())
        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
        End If
    End Sub
End Class
Posted 13-Apr-13 5:42am
Updated 13-Apr-13 6:19am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100