Results 1 to 8 of 8

Thread: Winsock

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    162

    Winsock

    Hi I was wondering if anyone had a very very very simple winsock control that just sent 1 packet to a server evey 5mins and when it stops the server takes off that pc

    What its for is a computer room so i can see what pc's are turned on and what arnt in use using a client server setup. Having never used winsock before I'm completely stuck looking at some of the tutorials

    Andy

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    162
    no one

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    just make a timer control and set the interval to 5000 and put this in it
    Wsk.SendData mydata
    doEvents

    and the server has to log the time that the last package has received.

  4. #4
    jmmcba
    Guest

    Exclamation

    My English are not very well but i development very system based in winsocket (UDP/TCP), tell me better and send the code for a better anwser !

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    162
    Thats the problem.

    I have no source atm and

    Code:
    just make a timer control and set the interval to 5000 and put this in it 
    Wsk.SendData mydata 
    doEvents 
    
    and the server has to log the time that the last package has received.
    is very helpfull but I'm still unsure on how to get the server to log its data and how to specify IP etc.

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehe, I think there is a better way!
    Make a winsock control array. You can identify each client with the index of the winsock control that the client is connected to. you can make a simple array that has the same number of elements that the winsock control has ( dim myArray (50) as string )

    put some code to store a ID for each computer when they connect

    VB Code:
    1. Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.      ' Do other stuff .....
    3.      myArray(index) = "Client #" & index
    4. End Sub
    5.  
    6.  
    7. Private Sub Winsock1_Close(Index As Integer)
    8.     MsgBox myArray (index) & " has logged off."
    9. End sub

    I'm not a very good programmer, so I'm sure there are better ways to do this!!! that might help you too

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    162
    Right so far I've done this
    Server =
    Code:
    Dim connection As Boolean
    Private Sub Form_Load()
    Winsock1.Close
    Winsock1.LocalPort = 1008
    Winsock1.Listen
    End Sub
    
    Private Sub Timer1_Timer()
    If connection = False Then text1.Text = ""
    connection = False
    End Sub
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
        If Winsock1.State <> sckClosed Then Winsock1.Close
        Winsock1.Accept requestID
    End Sub
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
        Dim strIncoming As String
        Winsock1.GetData strIncoming
      If text1.Text = "" Then
    text1.Text = strIncoming
    End If
        connection = True
    End Sub
    Private Sub Winsock1_close()
        Form_Load
    End Sub
    client =

    Code:
    Private Sub Form_Load()
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.RemotePort = 1008
    Winsock1.RemoteHost = ipadd.Text
    Winsock1.Connect
                Do Until Winsock1.State = sckConnected
                    DoEvents: DoEvents: DoEvents: DoEvents
                    If Winsock1.State = sckError Then
                        MsgBox "Problem connecting!"
                        Exit Sub
                    End If
                Loop
    End Sub
    Private Sub Timer1_Timer()
    Winsock1.SendData ("datatest1")
    End Sub
    I need to know how you can get more than 1 client ocnnecting at a time andhow to get the different clients to show in different text boxes.

    Andy

  8. #8
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by MrPolite
    just make a timer control and set the interval to 5000 and put this in it
    Wsk.SendData mydata
    doEvents
    It needs to be corrected...
    timer has mazimum interval of 65535 milisecods which is just over a minute. so you must keep conting each minute or you must use
    GetTickCount API function for this purpose

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width