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. freezing issue with simple client/server

freezing issue with simple client/server

Scheduled Pinned Locked Moved Visual Basic
helpcsharpsysadmindata-structures
3 Posts 2 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.
  • A Offline
    A Offline
    acecase
    wrote on last edited by
    #1

    Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and can't see that I am doing anything wrong (i obviousely am though) everything "works", client connects to server and when anything is sent to the server it starts the mp3 and passes all messages the way i ment for it to except that my server is supposed to display the data it recieves in a window (that worked untill i changed some things) and my server will hang after I pass a few strings to it from the client. The hanging is what I can't figure out. I can debug the other no problem. Anyway here is the code, please look over how sloppy it has gotten after hours of changeing things arround. Server : Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form 'Windows Form Designer Generated Code was here "removed for size of post" Const port As Int32 = 8353 Dim localIp As IPAddress = IPAddress.Parse("127.0.0.1") Dim server As New TcpListener(localIp, port) Dim netStream As NetworkStream Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'start tcplistener on localhost: 8353 server.Start() Try 'accept connections Dim client As TcpClient = server.AcceptTcpClient() 'get stream netStream = client.GetStream While netStream.CanRead And netStream.CanWrite 'read stream into a byte array Dim reciveBufferSize(client.ReceiveBufferSize) As Byte netStream.Read(reciveBufferSize, 0, CInt(client.ReceiveBufferSize)) 'convert data from the client into a usable string variable Dim dataFromClient As String = Encoding.ASCII.GetString(reciveBufferSize) 'do something with the data TextBox2.Text = dataFromClient 'send a response to the client Dim serverResponse As String = "Transmision completed" Dim sendBufferSize As [Byte]() = Encoding.ASCII.GetBytes(serverResponse) netStream.Write(sendBufferSize, 0, sendBufferSize.Length) 'show what was sent TextBox1.Text = serverResponse If dataFromClient.ToString > "" Then Syst

    C 1 Reply Last reply
    0
    • A acecase

      Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and can't see that I am doing anything wrong (i obviousely am though) everything "works", client connects to server and when anything is sent to the server it starts the mp3 and passes all messages the way i ment for it to except that my server is supposed to display the data it recieves in a window (that worked untill i changed some things) and my server will hang after I pass a few strings to it from the client. The hanging is what I can't figure out. I can debug the other no problem. Anyway here is the code, please look over how sloppy it has gotten after hours of changeing things arround. Server : Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form 'Windows Form Designer Generated Code was here "removed for size of post" Const port As Int32 = 8353 Dim localIp As IPAddress = IPAddress.Parse("127.0.0.1") Dim server As New TcpListener(localIp, port) Dim netStream As NetworkStream Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'start tcplistener on localhost: 8353 server.Start() Try 'accept connections Dim client As TcpClient = server.AcceptTcpClient() 'get stream netStream = client.GetStream While netStream.CanRead And netStream.CanWrite 'read stream into a byte array Dim reciveBufferSize(client.ReceiveBufferSize) As Byte netStream.Read(reciveBufferSize, 0, CInt(client.ReceiveBufferSize)) 'convert data from the client into a usable string variable Dim dataFromClient As String = Encoding.ASCII.GetString(reciveBufferSize) 'do something with the data TextBox2.Text = dataFromClient 'send a response to the client Dim serverResponse As String = "Transmision completed" Dim sendBufferSize As [Byte]() = Encoding.ASCII.GetBytes(serverResponse) netStream.Write(sendBufferSize, 0, sendBufferSize.Length) 'show what was sent TextBox1.Text = serverResponse If dataFromClient.ToString > "" Then Syst

      C Offline
      C Offline
      cnurse
      wrote on last edited by
      #2

      I'm not an expert on the sockets stuff, but my gut feeling makes me wonder if the loops you are in need a DoEvents to keep the events running through the rest of your application. You could also use the system.diagnostics namespace to get access to the Debug object and start writing some assert and trace statements, that will show where your code is stopping. It really might just be that it looks like its hung when in fact its in such a tight loop it can't do any of the event stuff it needs to do. So the doevents will yield for a time and let the system do its thing. Nursey

      A 1 Reply Last reply
      0
      • C cnurse

        I'm not an expert on the sockets stuff, but my gut feeling makes me wonder if the loops you are in need a DoEvents to keep the events running through the rest of your application. You could also use the system.diagnostics namespace to get access to the Debug object and start writing some assert and trace statements, that will show where your code is stopping. It really might just be that it looks like its hung when in fact its in such a tight loop it can't do any of the event stuff it needs to do. So the doevents will yield for a time and let the system do its thing. Nursey

        A Offline
        A Offline
        acecase
        wrote on last edited by
        #3

        Thanks, I haven't gottin real deap into the diagnostics namespaces but the whole purpose is to learn so I'll look into it. Defenetly sounds like a good thing to learn to use for debugging. Thanks again. 2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..

        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