Results 1 to 13 of 13

Thread: [2008] How to establish a connection between two computers?

  1. #1

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    [2008] How to establish a connection between two computers?

    Hello,

    I have a chat application. I want my app be able to create a server, and other people using the same app to be able to join others' servers, after that those two computers (I will at first have only max 2 guys/server) should be able to communicate.

    How would I start? I have no clues what so ever.

    Thanks for your help!

  2. #2
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: [2008] How to establish a connection between two computers?

    Im using Visual Studio 2008 Professional Edition
    .Net Framework 3.5

  3. #3

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    That's interesting, I'll take a look at it...

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] How to establish a connection between two computers?

    Yeah, you basically need the one hosting the server to listen to a port, then have the other users connect to that the server hosts IP and port.
    The TcpListener class provides listening functionallity.
    The TcpClient class can initiate communications with listening sockets.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    I have one problem with that code in http://www.vbforums.com/showthread.php?t=503294

    When I very first time start a listen server my firewall blocks the connection and popups "Would you like to allowed blaa blaa". That's ok, but the problem is that if my firewall blocks my program for even a sec, my program will throw an error. =(

    How would I modify the server code so that it will wait a sec so that a user can press Allow Connection from firewall ? Or maybe somehow modify it to keep trying to connect without throwing errors.

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] How to establish a connection between two computers?

    What code are you looking at specifically? Perito's attached code or the code that he's linking to?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    Quote Originally Posted by Atheist
    What code are you looking at specifically? Perito's attached code or the code that he's linking to?
    In this page http://www.vbforums.com/showthread.php?t=503294

    The two attached codes, I tried them and they work sweet. The only problem is that when I first time start the app my firewall blocks it initially and that causes the program to throw an error. The second time firewall acceps the connection and no errors occurs anymore.

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] How to establish a connection between two computers?

    And it is the server application causing this? Does it occur when you click the "Listen" button?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    Quote Originally Posted by Atheist
    And it is the server application causing this? Does it occur when you click the "Listen" button?
    Yes! Exactly. When I click listen my fw temporarily blocks the connection and ask me what to do, at this point my app crashes and I press Accept Connection. After I open app again and press Listen it connects successfully.
    Last edited by kaisellgren; Feb 5th, 2008 at 05:29 AM.

  10. #10

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    Okay everything is working great except I have slight problems...

    Code:
    Error	3	'GetStream' is not a member of 'Chatter.Client'.	C:\Documents and Settings\Kai\My Documents\Visual Studio 2008\Projects\Chatter\Chatter\Private.vb	9	38	Chatter
    This is the error I keep getting.

    I have a main form which is the client. In client I have a button "Open private chat window" which opens a private chat window. I have a private.vb form similar to my main chat window. The only problem is the above, my private.vb seems not to be able to use the connection code anymore, so:

    How to make a new form/window to use existing connection used by main.vb?

    Any help is much appreciated!

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] How to establish a connection between two computers?

    How does your code look right now?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12

    Thread Starter
    Addicted Member kaisellgren's Avatar
    Join Date
    Jan 2006
    Posts
    149

    Re: [2008] How to establish a connection between two computers?

    Quote Originally Posted by Atheist
    How does your code look right now?
    - I have ConnectedClient.vb that has the ConnectedClient class.
    - Server.vb is the form and the code for the server window
    - Client.vb is the client form and code
    - PrivateChat.vb is a private window form that tries to send message like Client.vb does, but only client.vb is able to do it, somehow it does not carry its codes over to PrivateChat.vb and I this is the code in PrivateChat (Cleaned out of buttons and useless code for you):

    Code:
    Imports System.Text
    Imports System.Net
    Imports System.IO
    
    Public Class PrivateChat
        Public Sub SendMessage(ByVal Msg As String)
            Dim sw As IO.StreamWriter
            Try
                sw = New IO.StreamWriter(Client.GetStream)
                sw.Write(Msg)
                sw.Flush()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SendMessage("test")
        End Sub
    End Class
    And it tells:
    Code:
    Error	3	'GetStream' is not a member of 'Chatter.Client'.	C:\Documents and Settings\Kai\My Documents\Visual Studio 2008\Projects\Chatter\Chatter\PrivateChat.vb	9	38	Chatter
    Any ideas?

  13. #13
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] How to establish a connection between two computers?

    Well, I'd suggest that you create a constructor in PrivateChat that takes a ConnectedClient argument. Then, upon creating a new PrivateChat form instance, you could simply pass a ConnecteClient instance to it and use that for communication.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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