Results 1 to 5 of 5

Thread: winsock question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    winsock question

    im making the client connect to the port on the ip (as the server is already listening on the same port for incoming connections)

    VB Code:
    1. Private Sub cmdConnect_Click()
    2.         WStcpClient.Close
    3.         WStcpClient.RemoteHost = txtServerIp.Text
    4.         WStcpClient.RemotePort = 15000
    5.         WStcpClient.Connect
    6. End Sub

    but sometimes it doesnt work on the first click of the button, i usually need to close the form, click the button again and then it connects, can someone give me any error checking code so i can print something like

    'Unable to connect to server, please try again'

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

    Re: winsock question

    The real question is "why can't you reconnect?". You should be able to reconnect at any time (unless the server has a single winsock control and it is connected to another client when you try to reconnect).

    Can you post/upload all of your code?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: winsock question

    im using my ip as the server, and clients conect to me

    VB Code:
    1. 'client side code..
    2.  
    3. Private Sub WStcpClient_Connect()
    4.     WStcpClient.SendData "sendt;" & txtNick.Text
    5. End Sub
    6.  
    7. 'serverside code
    8.  
    9.     If Left(msg, 5) = "sendt" Then
    10.         Dim incomingMsg() As String
    11.         incomingMsg = Split(msg, ";")
    12.    
    13.         username = incomingMsg(1)
    14.         users(Index) = incomingMsg(1)
    15.        
    16.         WStcpServer(Index).SendData "topic" & topic & username
    17.     End If

    as you see on successfull connection, the server sends the topic to the client, but sometimes the client doesnt get no topic,

  4. #4
    Addicted Member
    Join Date
    Mar 2003
    Posts
    206

    Re: winsock question

    VB Code:
    1. WStcpClient.SendData "sendt;" & txtNick.Text
    should be:
    VB Code:
    1. WStcpClient.SendData "sendt" & ";" & txtNick.Text
    server:
    VB Code:
    1. If Left$(msg, 5) = "sendt" Then
    2.         Dim incomingMsg() As String
    3.         incomingMsg = Split(msg, ";", Len(msg))
    4.    
    5.         username = incomingMsg(1)
    6.         users(Index) = incomingMsg(1)
    7.  
    8.         WStcpServer(Index).SendData "topic" & topic & username
    9.     End If
    correct?

    but why are you assigning both username and users to 1?

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

    Re: winsock question

    Pouncer:
    I put off responding to your last reply because I was somewhat frustated by its lack of content. What part of "Can you post/upload all of your code?" wasn't clear? We can't help you if you don't provide us with the requested information.

    Aphex:
    Please explain why you feel that
    Quote Originally Posted by Aphex
    VB Code:
    1. WStcpClient.SendData "sendt;" & txtNick.Text
    should be:
    VB Code:
    1. WStcpClient.SendData "sendt" & ";" & txtNick.Text
    Either way, the end results are identical.

    And, as for your question
    but why are you assigning both username and users to 1?
    It's not uncommon to store a value in 2 or more places.

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