Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hello

i have develop a server-client chat room using VB.Net

some how i only can make the client connect the server if i open it on the same computer

when i try to connect it using my laptop (server on desktop) all i get is "Cannot connect server"

this program connection is using port.

can i use IP address or computer name at my client to detect the server?

can teach me how to connect to the server please

thank you in advance

 

p.s if there is no way to connect/detect the server this way please tell me so that i can change my programming title

Posted
Could you post your existing code - it makes it easier to troubleshoot if we can see what is going on?

 

How are you currently connecting to the server from the client?

 

ok here is the current code i have

on the client side

'connect to server

Private Sub connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connect.Click

If portbox.Text <> "" Then

chatbox.AppendText("Requesting Connection..." & vbCrLf)

On Error GoTo err

myclient = New TcpClient(portbox.Text)

myclient.GetStream.BeginRead(mydata, 0, 1024, AddressOf DoRe, Nothing)

Status1.Panels(0).Text = "Requesting Connection..."

chatbox.AppendText("Connected..." & vbCrLf)

Status1.Panels(0).Text = "Connected to :" & portbox.Text

Timer1.Enabled = True

a = InputBox("Enter Nickname:")

Send("nick:" & a)

ipbox.Enabled = False

portbox.Enabled = False

Button1.Visible = False

sendbox.Enabled = True

Button4.Visible = True

End If

err: If sendbox.Enabled = False Then

chatbox.AppendText("Unable to resolve to Server...Please try again")

End If

End Sub

 

'read data from server

Private Sub DoRe(ByVal ar As IAsyncResult)

Dim intCo As Integer

 

Try

intCo = myclient.GetStream.EndRead(ar)

If intCo < 1 Then

chatbox.AppendText("Disconnected" & vbCrLf)

Exit Sub

End If

 

BuildString(mydata, 0, intCo)

 

myclient.GetStream.BeginRead(mydata, 0, 1024, AddressOf DoRe, Nothing)

Catch e As Exception

End Try

End Sub

 

and here is the server side

'open the server n port

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

On Error Resume Next

myport = InputBox("Enter Port:", "Port Settings")

myThread = New Thread(AddressOf DoList)

myThread.Start()

UpdateStatus("Server Active on port:" & myport)

End Sub

'start listen for clients

Private Sub DoList()

Try

myListener = New TcpListener(myport)

myListener.Start()

Do

Dim q As New Client(myListener.AcceptTcpClient)

AddHandler q.Connected, AddressOf OnConnected

AddHandler q.Disconnected, AddressOf OnDisconnected

AddHandler q.LineReceived, AddressOf OnLineReceived

myClients.Add(q.ID, q)

Loop Until False

Catch

End Try

End Sub

i hope you can help me

thank you

  • Administrators
Posted

In the client code you need to modify the line

myclient = New TcpClient(portbox.Text)

to include the address of the server you need to connect to

 

i.e.

myclient = New TcpClient(serverbox.Text, portbox.Text)

 

where serverbox is another textbox on the form allowing a user to enter the servers name or address.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

serverbox created but still not working

myclient = New TcpClient(serbox.Text, portbox.Text)

and i notice that this coding is always underline(error indication)

myListener = New TcpListener(myport)

 

i been thinking.. can i set the IP or the computer name of my desktop so that my client can connect the server directly through both port and IP/name or the coding is already working

i ask some of my friends and they say it could be the reason of firewall on both of my computer since im not the administrator, just a guest user

could this be the problem?

im asking this cause later the users of the application wont be administrator of the computer, so the aplication must be able to be used by guests

sorry for the trouble and thank you

Edited by shingo99
  • Administrators
Posted

When you say it still isn't working what errors do you get? What are you putting into the serverbox field (ip address of remote server, server name etc.)?

 

Also when you say the line

myListener = New TcpListener(myport)

has the error indicator on it if you hold your mouse over the line what error appears in the tooltip?

 

As to the other ideas: is there a firewall between you and the other computer?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

there is no error.. it just cant detect my server

normally if connected it will just say "Connected to server" else it will say "Cannot connect to server"

and "Cannot connect to server" is what it say on the textbox

 

while on the serverbox i put "localhost" and on the portbox i put "8080"

at the server i put the port as "8080" as default

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

On Error Resume Next

myport = 8080

myThread = New Thread(AddressOf DoListen)

myThread.Start()

UpdateStatus("Server Active on port:" & myport)

 

End Sub

as i say before my server run on ports cause this is all i know

i didnt learn about connection using IP

most of the coding i got from book that is available in library

 

as for the error myListener = New TcpListener(myport)

it say

"public sub new (port as integer) is obsolete: use TcpListener(IPAddress localaddr, int port)"

 

now im manage to get the administrator password and im using it and yes there is a firewall between my desktop and the laptop

thank you for your help

  • Administrators
Posted

If you put localhost into the serverbox field and run the server locally does it connect? If so things are still okay.

If you run the server remotely and put the server's name or ip address in serverbox does it now fail to connect?

If there is a firewall between the two boxes then this is probably blocking access to certain (most) ports and will prevent connection - you will need to either convince the network administrator to open the relevant port (may be hard to convince though) or try and run the server and client portions of the project on two machines without a firewall between them.

 

The warning you are getting about

myListener = New TcpListener(myport)

simply means that this is no longer the recomended way to setup a listner and this may not be supported in a future version of the framework.

You should probably use the following code instead

myListner= New TcpListner(IPAddress.Any,myport)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

ok the firewall is off but still not working

locally?

if you mean the server and the client on the same computer then yes it is working prefectly

but if you mean in local LAN (2 computers joining) then no

the server is always open but the only problem is that the client on laptop cannot "ping" the server on my desktop

i try opening the server on laptop and client on desktop and the result is the same

the client can only ping the server if it is in the same computer as the server

 

i have try the code modification

myListner= New TcpListner(IPAddress.Any,myport)

but still nothing

 

ok here is the summary of the current status

LAN connection clear

firewall off

server on

client cant ping server

thank you again for your help

Posted
What is the IP address and subnet mask of both the client and server?

what do you mean by subnet mask??

 

IP address in my coding??

i didnt put any

i just import some file

Imports System.Threading

Imports System.Net

Imports System.Net.Sockets

Private myThread As Thread

Private myListener As TcpListener

and this is all im using to connect

 

IP address for the LAN connection?

in both my laptop and desktop i have set the networking to the same proxy IP n port are the same

or did i do something wrong (internet option->LAN setting->Proxy server then address="127.82.0.1" port="8080")

 

any problem with the LAN setting?i set both to the same thing

  • Administrators
Posted

If you bring up a command prompt and type ipconfig it should tell you your TCP/IP address and subnet mask.

If you could do that on both the client and server what are the values for ip address, subnet mask and default gateway?

 

Setting a proxy server wouldn't really help as that will only be used by IE for access to the internet.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

If you could do that on both the client and server what are the values for ip address, subnet mask and default gateway?

 

ok im quite confuse here

both my client and server means....

i type ipconfig on my desktop so i just want to know should it be the same value as in both laptop and desktop?

i got my IP , submask value but gateway is null

  • Administrators
Posted

Gateway being empty is fine, you need the server and client to be configured with ip addresses that can comunicate - given that you cannot ping this seems unlikely.

The client and server should not have the same ip address, but it does need to be within the same network range.

Without understanding how networks or TCP/IP work will make writting any network software tricky. You may find the following links worth a read as they do explain a bit more of the basics.

http://www.wown.com/j_helmig/tcpip.htm

http://www.yale.edu/pclt/COMM/TCPIP.HTM

http://www.pcsupportadvisor.com/search/c04100.htm

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

ok thanks

so now all i have to do is

set the client to detect the server IP

that is provided after i type IPCONFIG in the command prompt

so that my client can communicate with the server using the desktop(server) IP address

am i correct?

Posted

yes it does connect

thank you so much for your help

can i know how to detect my computer IP via VB.Net coding?

if there is none then is fine.

cause i just want to display it out to make thing easier for other user to know the server IP address

thank you again for your help

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...