Vb.net client/server chat application trouble menu

User Tag List

Results 1 to 8 of 8
  1. #1
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Vb.net client/server chat application trouble

    Hey everyone. My latest project is a chat client/server. I was surfing around lazily, and i came across a tut that seemed simple enough for my purposes, and it seemed to be something good to learn off of. Heres my question.

    It seems that every tut that i looked at were only local chat applications, which doesnt really help me, considering the fact that i dont want to talk to myself. What im wondering, is if anyone could help me figure out how to make this program that i found host over the internet, as apposed to locally.

    Server
    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Module Module1
        Dim clientsList As New Hashtable
        Sub Main()
            Dim serverSocket As New TcpListener(8888)
            Dim clientSocket As TcpClient
            Dim infiniteCounter As Integer
            Dim counter As Integer
    
            serverSocket.Start()
            msg("Chat Server Started ....")
            counter = 0
            infiniteCounter = 0
            For infiniteCounter = 1 To 2
                infiniteCounter = 1
                counter += 1
                clientSocket = serverSocket.AcceptTcpClient()
    
                Dim bytesFrom(10024) As Byte
                Dim dataFromClient As String
    
                Dim networkStream As NetworkStream = _
                clientSocket.GetStream()
                networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
                dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
                dataFromClient = _
                dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
    
                clientsList(dataFromClient) = clientSocket
    
                broadcast(dataFromClient + " Joined ", dataFromClient, False)
    
                msg(dataFromClient + " Joined chat room ")
                Dim client As New handleClinet
                client.startClient(clientSocket, dataFromClient, clientsList)
            Next
    
            clientSocket.Close()
            serverSocket.Stop()
            msg("exit")
            Console.ReadLine()
        End Sub
    
        Sub msg(ByVal mesg As String)
            mesg.Trim()
            Console.WriteLine(" > " + mesg)
        End Sub
        Private Sub broadcast(ByVal msg As String, _
        ByVal uName As String, ByVal flag As Boolean)
            Dim Item As DictionaryEntry
            For Each Item In clientsList
                Dim broadcastSocket As TcpClient
                broadcastSocket = CType(Item.Value, TcpClient)
                Dim broadcastStream As NetworkStream = _
                        broadcastSocket.GetStream()
                Dim broadcastBytes As [Byte]()
    
                If flag = True Then
                    broadcastBytes = Encoding.ASCII.GetBytes(uName + " : " + msg)
                Else
                    broadcastBytes = Encoding.ASCII.GetBytes(msg)
                End If
    
                broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length)
                broadcastStream.Flush()
            Next
        End Sub
    
        Public Class handleClinet
            Dim clientSocket As TcpClient
            Dim clNo As String
            Dim clientsList As Hashtable
    
            Public Sub startClient(ByVal inClientSocket As TcpClient, _
            ByVal clineNo As String, ByVal cList As Hashtable)
                Me.clientSocket = inClientSocket
                Me.clNo = clineNo
                Me.clientsList = cList
                Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf doChat)
                ctThread.Start()
            End Sub
    
            Private Sub doChat()
                Dim infiniteCounter As Integer
                Dim requestCount As Integer
                Dim bytesFrom(10024) As Byte
                Dim dataFromClient As String
                Dim sendBytes As [Byte]()
                Dim serverResponse As String
                Dim rCount As String
                requestCount = 0
                For infiniteCounter = 1 To 2
                    infiniteCounter = 1
                    Try
                        requestCount = requestCount + 1
                        Dim networkStream As NetworkStream = _
                                clientSocket.GetStream()
                        networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
                        dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
                        dataFromClient = _
                            dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
                        msg("From client - " + clNo + " : " + dataFromClient)
                        rCount = Convert.ToString(requestCount)
    
                        broadcast(dataFromClient, clNo, True)
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                Next
            End Sub
    
        End Class
    End Module
    Client

    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Public Class Form1
        Dim clientSocket As New System.Net.Sockets.TcpClient()
        Dim serverStream As NetworkStream
        Dim readData As String
        Dim infiniteCounter As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
            Dim outStream As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(TextBox2.Text + "$")
            serverStream.Write(outStream, 0, outStream.Length)
            serverStream.Flush()
        End Sub
    
        Private Sub msg()
            If Me.InvokeRequired Then
                Me.Invoke(New MethodInvoker(AddressOf msg))
            Else
                TextBox1.Text = TextBox1.Text + Environment.NewLine + " > " + readData
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
            If TextBox4.Text = "" Then
                MsgBox("Please enter your server IP")
            Else
                If TextBox3.Text = "" Then
                    MsgBox("Please enter your name")
                Else
                    readData = "Conected to Chat Server ..."
                    msg()
                    clientSocket.Connect(TextBox4.Text, 8888)
                    'Label1.Text = "Client Socket Program - Server Connected ..."
                    serverStream = clientSocket.GetStream()
    
                    Dim outStream As Byte() = _
                    System.Text.Encoding.ASCII.GetBytes(TextBox3.Text + "$")
                    serverStream.Write(outStream, 0, outStream.Length)
                    serverStream.Flush()
    
                    Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf getMessage)
                    ctThread.Start()
                End If
            End If
        End Sub
    
        Private Sub getMessage()
            For infiniteCounter = 1 To 2
                infiniteCounter = 1
                serverStream = clientSocket.GetStream()
                Dim buffSize As Integer
                Dim inStream(10024) As Byte
                buffSize = clientSocket.ReceiveBufferSize
                serverStream.Read(inStream, 0, buffSize)
                Dim returndata As String = _
                System.Text.Encoding.ASCII.GetString(inStream)
                readData = "" + returndata
                msg()
            Next
        End Sub
    End Class
    Thanks in advanced.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

    Vb.net client/server chat application trouble
  2. #2
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Errm... what? You run your server, connect with your ip on port 8888, and the person you're talking to connects to your ip on port 8888 and it works.

  3. #3
    Fenryr's Avatar Member
    Reputation
    58
    Join Date
    Mar 2007
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wherever you put the ip address, put in the address of the server? i have a working version of a program that sends messages between client and server if you need more help.

  4. #4
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well it seemed like this chat service is client to server to client, so i want to make sure of a few things. The server is only run on one machine, correct? also the machine with the server running, do i need to forward the port 8888?? or just unblock it if it is blocked in a firewall. (ps, the ip is external ip correct?)

    Thanks.
    Last edited by Flame_Warrior; 07-23-2009 at 08:55 PM.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  5. #5
    The Maffyx's Avatar Contributor

    Reputation
    249
    Join Date
    Feb 2007
    Posts
    1,186
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most likely you will need to forward the port.


  6. #6
    Flame_Warrior's Avatar Member
    Reputation
    36
    Join Date
    Sep 2008
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it to work :]] had to forward the port. anyway now im wondering how to get the hash table into a textbox in the client, to let the user know who is online and who is offline. also i want a disconnect button. any ideas on how to do the hash table? Im going to mess around with the disconnect button, il probably be able to figure that out.

    Wofa.us = website in progress. beginning \\\\ ||||||||||done https://www.youtube.com/watch?v=NVFaGb3ZkBk=awesome vid!!

  7. #7
    zeeshangrw's Avatar Private
    Reputation
    1
    Join Date
    Oct 2010
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need user to know who is online, offline and also want a disconnect button for client end. I am receiving an error message at server side when i close the client application. The session of client application donot disconnects from running sockets when i close. please paste the code if some one has the solution or send me at [email protected]. thanks

  8. #8
    EmiloZ's Avatar Flying Piggy Back
    CoreCoins Purchaser
    Reputation
    538
    Join Date
    Jun 2007
    Posts
    1,393
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of having a computer running the server client 24/7, what about setting up a SQL database and link the chat client with MySQL module?
    Why fill up a signature?

Similar Threads

  1. [Request] VB.NET 2008 Voice Chat
    By EmiloZ in forum Programming
    Replies: 14
    Last Post: 04-11-2012, 09:32 AM
  2. [Release] Live Chat Client&Server
    By sve3nn in forum WoW EMU Programs
    Replies: 27
    Last Post: 03-27-2009, 05:25 PM
  3. [WotLK] Beta Client Server
    By Cypher in forum World of Warcraft Emulator Servers
    Replies: 12
    Last Post: 07-30-2008, 01:49 AM
  4. Oblivination Server Chat , right her e;))))
    By Illlidan in forum Community Chat
    Replies: 0
    Last Post: 04-16-2007, 08:53 AM
  5. MMOWNED IRC SERVER/CHat
    By LightWave in forum Community Chat
    Replies: 15
    Last Post: 08-27-2006, 09:06 AM
All times are GMT -5. The time now is 02:37 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search