Results 1 to 5 of 5

Thread: winsock between 2 projs

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    81

    winsock between 2 projs

    Hi,

    Can anyone tell me how to connect between 2 winsocks in different projs..

    ie.. I have one winsock in project1(a.VBP) which is acting as a server and I have one more winsock in another Project2(b.VBP) which should act as a client??

    I cant do it as the state is always "Connecting,,,,,,," and it is not establishing the connxn.

    Plz.........Help me out...
    Pls reply ASAP.

    Luv...........Ravindran

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    could be a thousand and one reasons...so grab yourself a ready-made example from here which you can mod to suit

    http://www.planetsourcecode.com/vb/s...t=Alphabetical

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    81

    Oh,,,No

    Hi,

    Ur thread doesnt gimme an example for wat i am looking for...Plz let me know whether it is possible at all....

    If so..Can anybody try it out and letme know..

    Else...
    Im posting my code here and anyone can fig out where i am going wrong...Just put the 2 forms in diff projs and try it out...
    Attached Files Attached Files
    Pls reply ASAP.

    Luv...........Ravindran

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Is your IP 10.100.102.16 ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Thumbs up Info.

    The problem might be with the IP. Is it valid?

    To see if your code works, you can test your projects on your local machine, using the local host IP "127.0.0.1".

    I just went through your code, and added a couple of things, such as connection closing etc.
    VB Code:
    1. 'frmServer.frm - added tcpserver_close event.
    2. Option Explicit
    3.  
    4. Private Sub Form_Load()
    5.     ' Set the LocalPort property to an integer.
    6.     ' Then invoke the Listen method.
    7.     tcpserver.LocalPort = 8000
    8.     tcpserver.Listen
    9.     'frmClient.Show ' Show the client form.? I thought this was the server project??
    10. End Sub
    11.  
    12. 'Just a little addition to listen again when the client closes.
    13. Private Sub tcpserver_Close()
    14.     'When the client closes, clear the text
    15.     txtOutput.Text = ""
    16.    
    17.     If tcpserver.State <> sckClosed Then
    18.         tcpserver.Close
    19.         DoEvents
    20.     End If
    21.    
    22.     'Listen again
    23.     tcpserver.Listen
    24. End Sub
    25.  
    26. Private Sub tcpserver_ConnectionRequest(ByVal requestID As Long)
    27.     ' Check if the control's State is closed. If not,
    28.     ' close the connection before accepting the new
    29.     ' connection.
    30.     If tcpserver.State <> sckClosed Then
    31.         tcpserver.Close
    32.     End If
    33.     ' Accept the request with the requestID
    34.     ' parameter.
    35.     tcpserver.Accept requestID
    36. End Sub
    37.  
    38. Private Sub tcpserver_DataArrival(ByVal bytesTotal As Long)
    39.     ' Declare a variable for the incoming data.
    40.     ' Invoke the GetData method and set the Text
    41.     ' property of a TextBox named txtOutput to
    42.     ' the data.
    43.     Dim strData As String
    44.     tcpserver.GetData strData
    45.     txtOutput.Text = txtOutput.Text & strData & vbCrLf
    46. End Sub
    47.  
    48. Private Sub txtSendData_Change()
    49.     ' The TextBox control named txtSendData
    50.     ' contains the data to be sent. Whenever the user
    51.     ' types into the  textbox, the  string is sent
    52.     ' using the SendData method.
    53.    
    54.     'Only send if we're connected
    55.     If tcpserver.State = sckConnected Then
    56.         tcpserver.SendData txtSendData.Text
    57.     End If
    58.    
    59. End Sub
    60.  
    61.  
    62.  
    63.  
    64. 'frmClient.frm - added a button named cmdClose.
    65. Option Explicit
    66.  
    67. Private Sub Form_Load()
    68.     'For testing, use the local host.
    69.     tcpClient.RemoteHost = "127.0.0.1"
    70.     tcpClient.RemotePort = 8000
    71. End Sub
    72.  
    73. Private Sub cmdConnect_Click()
    74.     tcpClient.Connect
    75. End Sub
    76.  
    77. 'Just a little addition to close the connection.
    78. Private Sub cmdClose_Click()
    79.  
    80.     If tcpClient.State <> sckClosed Then
    81.         'Clear output.
    82.         txtOutput.Text = ""
    83.         'Close
    84.         tcpClient.Close
    85.         DoEvents
    86.     End If
    87.    
    88. End Sub
    89.  
    90. Private Sub txtSend_Change()
    91.     'Only attempt to send if we're connected.
    92.     If tcpClient.State = sckConnected Then
    93.         tcpClient.SendData txtSend.Text
    94.     End If
    95. End Sub
    96.  
    97. Private Sub tcpClient_DataArrival _
    98.         (ByVal bytesTotal As Long)
    99.        
    100.     Dim strData As String
    101.     tcpClient.GetData strData
    102.     txtOutput.Text = txtOutput.Text & vbCrLf & strData
    103.    
    104. End Sub

    I tried the code above, using the local host, and it worked fine. Hope this helps.
    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

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