Help in winsock connection pls!

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2009
Posts: 13
Reputation: limesight18 is an unknown quantity at this point 
Solved Threads: 0
limesight18's Avatar
limesight18 limesight18 is offline Offline
Newbie Poster

Help in winsock connection pls!

 
0
  #1
Apr 16th, 2009
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub imgComputingG_Click(Index As Integer)
  2. Dim stSQL As String
  3. Dim stTimeIn As String
  4. On Error GoTo Err_Handling
  5.  
  6. If MsgBox("Start Unit#" & lblUnitNo(Index).Caption & " Timer?", vbQuestion + vbYesNo, "Start Timer") = vbYes Then
  7. Screen.MousePointer = vbHourglass
  8. 'bypass
  9. Sock.RemoteHost = "PC4" 'UnitPanel(Index).Tag
  10. Sock.SendData "1"
  11.  
  12. stTimeIn = Format$(Now, "mm/dd/yyyy hh:mm ampm")
  13. stSQL = "UPDATE UnitLocStats set Status = 'A',"
  14. stSQL = stSQL & " StartDateTime = #" & stTimeIn & "#"
  15. stSQL = stSQL & " Where Unit = " & Str2Fld(lblUnitNo(Index).Caption)
  16. gDB.Execute stSQL
  17.  
  18. lblUnitNo(Index).ForeColor = vbWhite
  19. lblDateCaption(Index).ForeColor = vbCyan
  20. lblStartTime(Index).ForeColor = vbWhite
  21. lblStartTime(Index).Caption = stTimeIn
  22.  
  23. imgComputing(Index).PictureAnimationEnabled = True
  24. imgComputing(Index).Visible = True
  25. imgComputingG(Index).Visible = False
  26. UnitPanel(Index).Refresh
  27.  
  28. Screen.MousePointer = vbDefault
  29. End If
  30. Exit Sub
  31.  
  32. Err_Handling:
  33. Screen.MousePointer = vbDefault
  34. If Err.Number = 438 Or Err.Number = 10014 Then
  35. MsgBox "Workstation currently unavailable ...", vbInformation, "Unavailable"
  36. Else
  37. MsgBox Err.Number & " - " & Err.Description & "...", vbInformation, "Error Encountered"
  38. End If
  39. End Sub

and here's for the client side

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Dim stCompName As String
  3. Dim stHostComputer As String
  4. Dim stHostPath As String
  5. Dim stStatus As String
  6. Dim stStartTime As String
  7. Dim lMins As Long
  8.  
  9.  
  10. Left = 0
  11. Top = 0
  12.  
  13. Sock.RemoteHost = GetSetting(App.Title, "Settings", "HostComputer", "SNAKE-EYES")
  14. Sock.RemotePort = 1001
  15. Sock.Bind 1002
  16.  
  17. stCompName = GetSetting(App.Title, "Settings", "ComputerName", vbNullString)
  18. stHostComputer = GetSetting(App.Title, "Settings", "HostComputer", vbNullString)
  19. stHostPath = GetSetting(App.Title, "Settings", "DBPath", "C:\Projects\TMS\TMS.MDB")
  20. If stCompName = vbNullString Or stHostComputer = vbNullString Or stHostPath = vbNullString Then
  21. frmSettings.Show vbModal
  22. End If
  23.  
  24. stStatus = GetSetting(App.Title, "Settings", "Status", "Locked")
  25. stStartTime = GetSetting(App.Title, "Settings", "StartTime", vbNullString)
  26. If stStatus = "Locked" Then
  27. Call LockWorkStation
  28. Else
  29. lMins = CLng((Now - CDate(stStartTime)) * 1440)
  30. If lMins >= 60 Then
  31. mbyHrs = CByte(lMins / 60)
  32. mbyMins = lMins Mod 60
  33. mbySecs = 0
  34. Else
  35. mbyMins = lMins
  36. End If
  37. Timer1.Enabled = True
  38. End If
  39.  
  40.  
  41. End Sub

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
  2. Dim stData As String
  3. On Error GoTo Err_Handler
  4.  
  5. Sock.GetData stData
  6. Select Case Mid(stData, 1, 1)
  7. Case "0" 'Lock Workstation and Stop Timer
  8. Timer1.Enabled = False
  9. Call LockWorkStation
  10. Call SaveSetting(App.Title, "Settings", "Status", "Locked")
  11. Case "1" 'Unlock Workstation and Start Timer
  12. Call UnlockWorkStation
  13. Call Reset
  14. Call SaveSetting(App.Title, "Settings", "Status", "Unlocked")
  15. Call SaveSetting(App.Title, "Settings", "StartTime", Now)
  16. Case "2" 'Confirm Order
  17. MsgBox "Thankyou !!! Your Order(s) and Message have been received...", vbInformation, "Orders Confirmed"
  18. Unload frmMenuToday
  19. Case "3" 'Message
  20. cmdOrder.PlaySoundFile "Notice.wav"
  21. MsgBox Mid$(stData, 2), vbInformation + vbOKOnly, "Message from Counter"
  22. Case "4" 'Lock Workstation w/o stopping Timer Settings
  23. Call LockWorkStation
  24. Case "5" 'Unlock Workstation w/o stopping Timer Settings
  25. Call UnlockWorkStation
  26. Case "6" 'Shutdown Workstation
  27. Call ShutdownWorkstation
  28. End Select
  29. Exit Sub
  30.  
  31. Err_Handler:
  32. Screen.MousePointer = vbDefault
  33. MsgBox Err.Number & " - " & Err.Description & " ...", "Error Encountered"
  34.  
  35. End Sub

pls help me
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Help in winsock connection pls!

 
0
  #2
Apr 19th, 2009
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).
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: limesight18 is an unknown quantity at this point 
Solved Threads: 0
limesight18's Avatar
limesight18 limesight18 is offline Offline
Newbie Poster

Re: Help in winsock connection pls!

 
0
  #3
Apr 19th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 140
Reputation: jonifen is an unknown quantity at this point 
Solved Threads: 15
jonifen jonifen is offline Offline
Junior Poster

Re: Help in winsock connection pls!

 
0
  #4
Apr 21st, 2009
.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/libr...09(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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: limesight18 is an unknown quantity at this point 
Solved Threads: 0
limesight18's Avatar
limesight18 limesight18 is offline Offline
Newbie Poster

Re: Help in winsock connection pls!

 
0
  #5
Apr 22nd, 2009
thank you! for the help sir, im now making progress on what im doing..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC