monkeyiam's Profile User Rating: -----

Reputation: 3 Apprentice
Active Members
Active Posts:
63 (0.05 per day)
27-March 11
Profile Views:
Last Active:
User is offline Jun 22 2013 09:06 AM

Previous Fields

Dream Kudos:
Icon   monkeyiam has not set their status

Posts I've Made

  1. In Topic: get selected value\s of listbox bound to datatable

    Posted 22 Mar 2013

    View PostCharlieMay, on 21 March 2013 - 07:15 PM, said:

    I don't use a listbox much but I'm thinking obj.SelectedItem (or obj.SelectedItem.ToString) is what you want. It may even be obj.SelectedItem.Text


    I can't get that far as the error is caused by the for each loop.

    I am not sure how else to write it.

  2. In Topic: Select case and ASCII encoding

    Posted 3 Dec 2012

    Cool, that did the trick and all is working now.

  3. In Topic: Select case and ASCII encoding

    Posted 3 Dec 2012

    I tried to upload the zipped project but I was told I am not permitted to do so. I'll paste it in. The final agent app will run as a service but for testing purposes I am using a windows form.

    Listening Agent

    Imports System.Net.Sockets
    Imports System.Threading
    Imports System.Text
    Public Class Form1
        Dim serverSocket As System.Net.Sockets.TcpListener
        Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName()).AddressList(0)
        Dim ipLocalEndPoint As New System.Net.IPEndPoint(ipAddress, 8888)
        Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Dim listenThread As New Thread(New ThreadStart(AddressOf ListenForClients))
        End Sub
        Private Sub ListenForClients()
            serverSocket = New TcpListener(ipLocalEndPoint)
            While True   'blocks until a client has connected to the server
                Dim client As TcpClient = Me.serverSocket.AcceptTcpClient()
                Dim clientThread As New Thread(New ParameterizedThreadStart(AddressOf HandleClientComm))
            End While
        End Sub
        Private Sub HandleClientComm(ByVal client As Object)
            Dim tcpClient As TcpClient = DirectCast(client, TcpClient)
            Dim clientStream As NetworkStream = tcpClient.GetStream()
            Dim message As Byte() = New Byte(10024) {}
            'Dim message As Byte()
            Dim bytesRead As Integer
            While True
                bytesRead = 0
                bytesRead = clientStream.Read(message, 0, 10024)  'blocks until a client sends a message
                If bytesRead = 0 Then
                    Exit While    'the client has disconnected from the server
                End If
                'message has successfully been received
                'Dim encoder As New ASCIIEncoding()
                Dim serverResponse As String = "I have received your message"
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(serverResponse)
                clientStream.Write(sendBytes, 0, sendBytes.Length)
                'Dim mymessage = ASCIIBytesToString(message)
                Dim mymessage as string = Encoding.ASCII.GetString(message)
                ' Dim mymessage = encoder.GetString(message)
                'mymessage = "test"
                Select Case mymessage
                    Case "test"
                    Case "test1"
                End Select
            End While
        End Sub
        Private Function ASCIIBytesToString(ByVal bytes() As Byte) As String
            Return Encoding.ASCII.GetString(bytes)
        End Function
        Public Sub LeaveDomain()
            MsgBox("I am leaving the domain")
        End Sub
        Public Sub JoinDomain()
            MsgBox("I have joined the domain")
        End Sub

    Connecting client

    Imports System.Net.Sockets
    Imports System.Text
    Public Class Form1
        Dim ClientSocket As New TcpClient
        Dim ServerStream As NetworkStream
        Dim ServerAddress As String = ""  ' Set the IP address of the server
        Dim PortNumber As Integer = 8888      ' Set the port number used by the server
        Dim OutStream As Byte() = Encoding.ASCII.GetBytes("test")
        Dim ReceivedData As String
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            ClientSocket.Connect(ServerAddress, PortNumber)
            Dim inStream(10024) As Byte
            ServerStream = ClientSocket.GetStream()
            ServerStream.Write(OutStream, 0, OutStream.Length)
            ServerStream.Read(inStream, 0, CInt(ClientSocket.ReceiveBufferSize))
            ReceivedData = Encoding.ASCII.GetString(inStream)
        End Sub
        Private Sub HandleReceivedDate(ByVal msg As String)
        End Sub

    Thanks for the assistance so far :o/>/>)
  4. In Topic: Select case and ASCII encoding

    Posted 3 Dec 2012

    View Postlucky3, on 03 December 2012 - 11:25 AM, said:

    Try to change Select Case to If statement, and see if there is a difference.

    I already tried that before posting. I have even tried using trim to be sure there is no white space. It is very strange.
  5. In Topic: Select case and ASCII encoding

    Posted 3 Dec 2012

    View Postlucky3, on 03 December 2012 - 07:02 AM, said:

    Try this:

    Imports System.Text
    Module Module1
        Sub Main()
            Dim message() As Byte = Encoding.ASCII.GetBytes("test")
            Dim mymessage As String = Encoding.ASCII.GetString(message)
            Select Case mymessage  'if you put breakpoint here, you'll see that mymessage is "test", and it will execute LeaveDomain()
                Case "test"
                Case "test1"
            End Select
        End Sub
        Sub LeaveDomain()
            Console.WriteLine("LeaveDomain sub")
        End Sub
        Sub JoinDomain()
            Console.WriteLine("JoinDomain sub")
        End Sub
    End Module

    Your code works fine. Yet in my code, I put the break point in exactly the same place, I see that test is assigned to mymessage but still it fails.

    It must be something to d with this portion of the code:

    Dim message As Byte() = New Byte(4095) {}

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


monkeyiam hasn't added any friends yet.


monkeyiam has no profile comments yet. Why not say hello?