Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. No Connection?

No Connection?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpgame-devsysadminhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    teknozwizard
    wrote on last edited by
    #1

    I'm trying to make a client to a text based game. I've asked the question before, but now I've got a little bit more to work with. What I need is some help with it. I'll show the code first. Code for my 'tcpListener' which I've actually added to my overall project as a Console Application - Module1

    Imports System.Net.Sockets
    Imports System.Text
    Module Module1
    Sub Main()
    Dim tcpListener As New TcpListener(6100)
    Dim requestCount As Integer
    Dim clientSocket As TcpClient
    tcpListener.Start()
    msg("Server Started")
    clientSocket = tcpListener.AcceptTcpClient()
    msg("Accept connection from client")
    requestCount = 0

        While (True)
            Try
                requestCount = requestCount + 1
                Dim networkStream As NetworkStream = \_
                        clientSocket.GetStream()
                Dim bytesFrom(10024) As Byte
                networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
                Dim dataFromClient As String = \_
                        System.Text.Encoding.ASCII.GetString(bytesFrom)
                dataFromClient = \_
            dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
                msg("Data from client -  " + dataFromClient)
                Dim serverResponse As String = \_
                    "Server response " + Convert.ToString(requestCount)
                Dim sendBytes As \[Byte\]() = \_
                    Encoding.ASCII.GetBytes(serverResponse)
                networkStream.Write(sendBytes, 0, sendBytes.Length)
                networkStream.Flush()
                msg(serverResponse)
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End While
    
    
        clientSocket.Close()
        tcpListener.Stop()
        msg("exit")
        Console.ReadLine()
    End Sub
    
    Sub msg(ByVal mesg As String)
        mesg.Trim()
        Console.WriteLine(" >> " + mesg)
    End Sub
    

    End Module

    And this is my code for the actual client

    Imports System.Net.Sockets
    Imports System.Text
    Public Class lokMudClient
    Dim clientSocket As New System.Net.Sockets.TcpClient()
    Dim serverStream As NetworkStream

    Private Sub btnConnect\_Click(ByVal sender As System.Object, \_
        ByVal e As System.EventArgs) Handles btnConnect.Click
        Dim serverStream As NetworkStream = clientSocket.GetStream()
        Dim buffSize As Integer
        Dim outStream As B
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups