DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Socket programming.... (http://www.daniweb.com/forums/thread201134.html)

scsachira Jul 2nd, 2009 3:31 am
Socket programming....
 
I'm designing chat application these days.. I tried several samples which i found from the web..
I designed Server and Client..
When i run client in my machine, server get it nicely..
but when server in my machine and client in other machine, server doesn't detect client..
I tried 5+ samples from the web.. every sample work like that.

In here we have dynamic IP address. is that the reason for my problem?
Is server need static IP address?

Give me help please... I'm totally stuck in here...

GeekByChoiCe Jul 2nd, 2009 11:12 am
Re: Socket programming....
 
Is your server behind a router? if so just set the portforwarding to the port the server is using and forward it to the machine on what the server is running.
And also make sure the Client is connecting to the right IP and port

scsachira Jul 2nd, 2009 11:22 am
Re: Socket programming....
 
Quote:

Originally Posted by GeekByChoiCe (Post 906498)
Is your server behind a router? if so just set the portforwarding to the port the server is using and forward it to the machine on what the server is running.
And also make sure the Client is connecting to the right IP and port

I'm using ADSL modem to connect to Net..
I checked IP and port.. Both are same in the server and client.

Actually I'm selfstuding VB.net. Therefore, if u can give me code sample for it, it's vary valuble for me.

However thanks for Reply....

GeekByChoiCe Jul 3rd, 2009 4:24 am
Re: Socket programming....
 
1 Attachment(s)
source code is attached. this is a VERY basic server/client application

for adjusting:
in the client application just change it to your needs ...
Private Sub BGW1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGW1.DoWork
        Try
            myClient = New TcpClient("localhost", 5000)
            BGW1.ReportProgress(100)
        Catch ex As SocketException
            e.Result = "offline"
        End Try
    End Sub

in the server App:

    Private Sub DoListen()
        Try
            Listener = New TcpListener(Dns.GetHostEntry("localhost").AddressList(0), 5000)
            Listener.Start()

            Do
                Dim connectedClients As New clientClass(Listener.AcceptTcpClient)
                AddHandler connectedClients.Disconnected, AddressOf connectedClients_Disconnected
                AddHandler connectedClients.LineReceived, AddressOf connectedClients_LineReceived
                Clients.Add(connectedClients.ID, connectedClients)
            Loop Until False

        Catch
        End Try
    End Sub

hope it helps

scsachira Jul 4th, 2009 6:45 am
Re: Socket programming....
 
Hey... GeekByChoiCe..
Problem was solved..
Thanks for help me..
Thank u very much..
U r great..


All times are GMT -4. The time now is 4:45 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC