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

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

Previous Fields

Dream Kudos:
0
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


    Hi,

    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.

    Cheers
  2. In Topic: Select case and ASCII encoding

    Posted 3 Dec 2012

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

    :bananaman:
  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))
            listenThread.Start()
    
        End Sub
    
        Private Sub ListenForClients()
    
            serverSocket = New TcpListener(ipLocalEndPoint)
            serverSocket.Start()
            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))
                clientThread.Start(client)
            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
                'MsgBox(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"
                'MsgBox(mymessage)
    
                Console.WriteLine(mymessage)
    
                Select Case mymessage
    
                    Case "test"
                        LeaveDomain()
                    Case "test1"
                        JoinDomain()
                End Select
    
    
            End While
    
            tcpClient.Close()
        
        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 = "192.168.1.99"  ' 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.Flush()
    
            ServerStream.Read(inStream, 0, CInt(ClientSocket.ReceiveBufferSize))
            ReceivedData = Encoding.ASCII.GetString(inStream)
            HandleReceivedDate(ReceivedData)
    
    
    
        End Sub
        Private Sub HandleReceivedDate(ByVal msg As String)
            'MsgBox(msg)
        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"
                    LeaveDomain()
                Case "test1"
                    JoinDomain()
            End Select
    
            Console.ReadLine()
        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:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

monkeyiam hasn't added any friends yet.

Comments

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