a i have a existing project here, it's a Cafe management for computer shops..

my problem is with the connection..

when is try to send a packet to the client..

the client wont react...
i dont know if the client side just cant receive the packets the server send..
or
the server didn't send the packet properly..

i been trouble with this for days..
since.. i cant detect the problem..

here the code for the send-button on the server side

Private Sub imgComputingG_Click(Index As Integer)
    Dim stSQL As String
    Dim stTimeIn As String
    On Error GoTo Err_Handling
    
    If MsgBox("Start Unit#" & lblUnitNo(Index).Caption & " Timer?", vbQuestion + vbYesNo, "Start Timer") = vbYes Then
        Screen.MousePointer = vbHourglass
        'bypass
        Sock.RemoteHost = "PC4" 'UnitPanel(Index).Tag
        Sock.SendData "1"
        
        stTimeIn = Format$(Now, "mm/dd/yyyy hh:mm ampm")
        stSQL = "UPDATE UnitLocStats set Status = 'A',"
        stSQL = stSQL & " StartDateTime = #" & stTimeIn & "#"
        stSQL = stSQL & " Where Unit = " & Str2Fld(lblUnitNo(Index).Caption)
        gDB.Execute stSQL

        lblUnitNo(Index).ForeColor = vbWhite
        lblDateCaption(Index).ForeColor = vbCyan
        lblStartTime(Index).ForeColor = vbWhite
        lblStartTime(Index).Caption = stTimeIn
        
        imgComputing(Index).PictureAnimationEnabled = True
        imgComputing(Index).Visible = True
        imgComputingG(Index).Visible = False
        UnitPanel(Index).Refresh
        
        Screen.MousePointer = vbDefault
    End If
    Exit Sub
    
Err_Handling:
    Screen.MousePointer = vbDefault
    If Err.Number = 438 Or Err.Number = 10014 Then
        MsgBox "Workstation currently unavailable ...", vbInformation, "Unavailable"
    Else
        MsgBox Err.Number & " - " & Err.Description & "...", vbInformation, "Error Encountered"
    End If
End Sub

and here's for the client side

Private Sub Form_Load()
    Dim stCompName As String
    Dim stHostComputer As String
    Dim stHostPath As String
    Dim stStatus As String
    Dim stStartTime As String
    Dim lMins As Long
    

    Left = 0
    Top = 0
    
    Sock.RemoteHost = GetSetting(App.Title, "Settings", "HostComputer", "SNAKE-EYES")
    Sock.RemotePort = 1001
    Sock.Bind 1002
    
    stCompName = GetSetting(App.Title, "Settings", "ComputerName", vbNullString)
    stHostComputer = GetSetting(App.Title, "Settings", "HostComputer", vbNullString)
    stHostPath = GetSetting(App.Title, "Settings", "DBPath", "C:\Projects\TMS\TMS.MDB")
    If stCompName = vbNullString Or stHostComputer = vbNullString Or stHostPath = vbNullString Then
        frmSettings.Show vbModal
    End If
    
    stStatus = GetSetting(App.Title, "Settings", "Status", "Locked")
    stStartTime = GetSetting(App.Title, "Settings", "StartTime", vbNullString)
    If stStatus = "Locked" Then
        Call LockWorkStation
    Else
        lMins = CLng((Now - CDate(stStartTime)) * 1440)
        If lMins >= 60 Then
            mbyHrs = CByte(lMins / 60)
            mbyMins = lMins Mod 60
            mbySecs = 0
        Else
            mbyMins = lMins
        End If
        Timer1.Enabled = True
    End If


End Sub
Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
    Dim stData As String
    On Error GoTo Err_Handler
    
    Sock.GetData stData
    Select Case Mid(stData, 1, 1)
        Case "0"          'Lock Workstation and Stop Timer
            Timer1.Enabled = False
            Call LockWorkStation
            Call SaveSetting(App.Title, "Settings", "Status", "Locked")
        Case "1"          'Unlock Workstation and Start Timer
            Call UnlockWorkStation
            Call Reset
            Call SaveSetting(App.Title, "Settings", "Status", "Unlocked")
            Call SaveSetting(App.Title, "Settings", "StartTime", Now)
        Case "2"          'Confirm Order
            MsgBox "Thankyou !!! Your Order(s) and Message have been received...", vbInformation, "Orders Confirmed"
            Unload frmMenuToday
        Case "3"          'Message
            cmdOrder.PlaySoundFile "Notice.wav"
            MsgBox Mid$(stData, 2), vbInformation + vbOKOnly, "Message from Counter"
        Case "4"          'Lock Workstation w/o stopping Timer Settings
            Call LockWorkStation
        Case "5"          'Unlock Workstation w/o stopping Timer Settings
            Call UnlockWorkStation
        Case "6"          'Shutdown Workstation
            Call ShutdownWorkstation
    End Select
    Exit Sub
    
Err_Handler:
    Screen.MousePointer = vbDefault
    MsgBox Err.Number & " - " & Err.Description & " ...", "Error Encountered"
    
End Sub

pls help me

Recommended Answers

All 4 Replies

Does the client connect to the server OK first of all?
If you cant connect, then its likely to be related to a networking issue (i.e. a firewall stopping the connection going through).

Are you using TCP or UDP for the connection also? UDP would use the .Bind command (from my experience) whereas the TCP would use .Listen at the receiving end (the server where the clients connect to) and .Connect at the initiating end (the client which is connecting to a server).

Are you using TCP or UDP for the connection also?

yes sir, its using a UDP, ive tried checking the firewall setting, still the same,

when ever i try to send a packet to the client (ex, Start the time of the client)
there's no "Data_arrival" happening on the client side..

also can you pls sir explain to me the .bind command? thx for the reply sir!

.Bind is used in UDP to "attach" the application to a particular local port. Whereas .Listen is used in TCP to allow clients to connect according to the LocalPort provided.

There is a bit more detail about it here: http://msdn.microsoft.com/en-us/library/aa733709(VS.60).aspx

I've not used UDP much, only when making a game server query tool a while back, so I have referred to the link I gave you just then and I think that you would need to include the RemotePort in the server code, and also bind the control to a local port even though it is classed as the server.
The MSDN link advises that the RemoteHost, RemotePort and Bind are to be used on both client and server.

Hope that helps...

thank you! for the help sir, im now making progress on what im doing..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.