[Server question] menu

User Tag List

Results 1 to 6 of 6
  1. #1
    Lynie's Avatar Contributor
    Reputation
    87
    Join Date
    Mar 2008
    Posts
    74
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Server question]

    Hello,

    I was wondering how to let more then one client connect witht he server using TCP.
    Here is what I have right now.

    Server
    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Module Module1
        Private Const port As Integer = 3724
        Private Const MAX_SLOTS As Integer = 20
    
        Sub Main()
            Dim tcpServer As New TcpListener(port)
            Dim stream As NetworkStream
            tcpServer.Start()
            Console.WriteLine("Server started.")
            Console.WriteLine("Waiting for connections...")
            Dim tcpUser As TcpClient
            Try
                tcpUser = tcpServer.AcceptTcpClient()
                stream = tcpUser.GetStream()
                Console.WriteLine("Connection accepted.")
    
    
                Dim bytesText(tcpUser.ReceiveBufferSize) As Byte
                Dim strText As String
                Dim i As Integer = 0
    
                While True
                    stream.Read(bytesText, 0, tcpUser.ReceiveBufferSize)
                    strText = Encoding.ASCII.GetString(bytesText)
                    Console.WriteLine(strText)
                    strText = Nothing
                    i = i + 1
                    Console.SetCursorPosition(0, 3 + i)
                End While
                tcpUser.Close()
                tcpServer.Stop()
            Catch ex As Exception
                Console.WriteLine("Fail to recieve from client. " & ex.Message)
                Console.ReadLine()
                Main()
            End Try
        End Sub
    
    End Module
    client
    Code:
    Imports System.Net.Sockets
    Imports System.Text
    
    Public Class Form1
        Private tcpUser As New TcpClient
        Private stream As NetworkStream
        Private bytesText As [Byte]()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                tcpUser.Connect("127.0.0.1", 3724)
                tcpUser.GetStream()
                stream = tcpUser.GetStream()
            Catch ex As Exception
                MessageBox.Show("Unable to connect. " & ex.Message, "Error")
            End Try
        End Sub
    
        Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
            bytesText = Encoding.ASCII.GetBytes(txtMessage.Text)
            stream.Write(bytesText, 0, bytesText.Length)
        End Sub
    End Class
    Last edited by Lynie; 08-25-2008 at 12:27 PM. Reason: Edited

    [Server question]
  2. #2
    Erra's Avatar Member
    Reputation
    10
    Join Date
    Apr 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I do in VB6, is that I load a new instance of another winsock control when I get a connection to the first winsock control and then I accept the request on the later one.

    I think you could do something similar in VB .NET?

  3. #3
    Lynie's Avatar Contributor
    Reputation
    87
    Join Date
    Mar 2008
    Posts
    74
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm gonna try that. + rep. thanks for fast reply.

  4. #4
    Erra's Avatar Member
    Reputation
    10
    Join Date
    Apr 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, noticed it when checking for replies in my own thread :P

  5. #5
    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)
    Actually, winsock doesn't exist in vb.net, but you CAN still do a number of things to do requests (namely webrequest and webresponse). I'd say your principle is right, though. Just create another when one gets connected to.

  6. #6
    Erra's Avatar Member
    Reputation
    10
    Join Date
    Apr 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ReidE96 View Post
    Actually, winsock doesn't exist in vb.net, but you CAN still do a number of things to do requests (namely webrequest and webresponse). I'd say your principle is right, though. Just create another when one gets connected to.
    That's what I meant, for him to use the principle with whatever works in .NET

Similar Threads

  1. Emulator server question
    By Durgoax in forum World of Warcraft General
    Replies: 0
    Last Post: 01-06-2007, 02:51 AM
  2. Lots of Private Server Questions
    By slothahoy in forum World of Warcraft General
    Replies: 2
    Last Post: 12-08-2006, 06:39 PM
  3. Private Server Question
    By Ariakan in forum World of Warcraft General
    Replies: 0
    Last Post: 11-12-2006, 10:47 PM
  4. Couple Private Server questions
    By Jboz in forum World of Warcraft General
    Replies: 21
    Last Post: 07-26-2006, 07:37 PM
  5. Wow Emu server question
    By TripleShank26 in forum World of Warcraft General
    Replies: 2
    Last Post: 07-06-2006, 03:07 PM
All times are GMT -5. The time now is 05:39 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