|
-
Feb 3rd, 2008, 07:23 AM
#1
Thread Starter
Addicted Member
[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!
-
Feb 3rd, 2008, 08:19 AM
#2
Addicted Member
Re: [2008] How to establish a connection between two computers?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Feb 3rd, 2008, 08:21 AM
#3
Thread Starter
Addicted Member
Re: [2008] How to establish a connection between two computers?
 Originally Posted by perito
That's interesting, I'll take a look at it...
-
Feb 3rd, 2008, 08:32 AM
#4
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.
-
Feb 3rd, 2008, 09:10 AM
#5
Thread Starter
Addicted Member
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.
-
Feb 3rd, 2008, 09:20 AM
#6
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?
-
Feb 3rd, 2008, 09:22 AM
#7
Thread Starter
Addicted Member
Re: [2008] How to establish a connection between two computers?
 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.
-
Feb 3rd, 2008, 09:27 AM
#8
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?
-
Feb 3rd, 2008, 09:30 AM
#9
Thread Starter
Addicted Member
Re: [2008] How to establish a connection between two computers?
 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.
-
Feb 3rd, 2008, 12:41 PM
#10
Thread Starter
Addicted Member
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!
-
Feb 3rd, 2008, 04:18 PM
#11
Re: [2008] How to establish a connection between two computers?
How does your code look right now?
-
Feb 5th, 2008, 05:25 AM
#12
Thread Starter
Addicted Member
Re: [2008] How to establish a connection between two computers?
 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?
-
Feb 5th, 2008, 06:24 AM
#13
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|