Datanizze 0 Newbie Poster

ooo yes I did.. but it might not have worked ;) I'll try again then :cool:

Datanizze 0 Newbie Poster

(oops dual posts)

Datanizze 0 Newbie Poster

I don't understand your note!!

hehe.. I added your answer to your reputation by clicking
"Add to RamyMahrous's Reputation" as a thank you for helping me.

Datanizze 0 Newbie Poster

thank you for the link! It worked (environment.exit)

However, at first I put the code in the wrong places making it quit a liiiittle too soon :D all fixed now (I think) :P ... but you know programming, solving one problem -> 10 new problems appears MAGICALLY :)

PS
Thou shall receive a reputation-link-click from me now :twisted:

Datanizze 0 Newbie Poster

The clienthandler is a class I created which contains the clients Name, Thread & socket (tcpclient)

Sub ShutDown()
        Try
'here is the loop for the clients threads
            For n As Integer = 0 To ClientArray.Count - 1
                Dim ch As clienthandler = CType(ClientArray(n), clienthandler)
                Broadcast(ch, "QUIT|")
                ch.Sock.Close()
                ch.CLThread.Abort()
            Next
            DoListen = False
            listener.Stop()
'and this is for a listen loop that checks for incoming connections
            If ListenThread IsNot Nothing AndAlso ListenThread.IsAlive Then
                ListenThread.Abort()
            End If
        Catch ex As Exception
            MsgBox("(166): " & ex.Message & vbCrLf & vbCrLf & ">> Om du inte kan tyda detta felmeddelande kontakta Datanizze <<")
        End Try
        Me.Close()
    End Sub
Datanizze 0 Newbie Poster

That's not really what I want to do, It's for a chat program with each client having it's own thread to work on, so when the server is to shut down the loop sends a message to each connected client that it is shutting down, after that the thread is aborted.

So I don't really know why it won't shut down since the close sub checks if they are still alive and if so it terminates the thread :(

Datanizze 0 Newbie Poster

Hi! I have a slight problem with multithreading.

There is many threads active in the application
and they are all kept in an arraylist.

so when I try to quit the program, it loops through the arraylist and exits all the threads....

but something else is making the program "unwilling" to shut down, leaving it invisible, still running...

So I was wondering if there is a way to get ALL active (stillAlive) threads in the application and terminate them?

Datanizze 0 Newbie Poster

Just here to tell you I've solved it! :D

Step by step from the error I went back to eventually find that the problem were between the retrival of the bytes and the conversion to string which ended in the string did not convert entirely, leaving me without the finishing ", therefore the problems, solving this also solved many of my previous problems :D I'm kinda' happy right now :P

Datanizze 0 Newbie Poster

Thanks for trying though Minolwen :)

As you (maybe) can see in the attachment image, I AM forwarding the whole message to the msg sub, but only the tokens(1) gets through :(

Datanizze 0 Newbie Poster

I know this is csharp corner but the article is on vb.net

http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithStringsP311232005021723AM/WorkingWithStringsP3.aspx

That's a very useful link and I thank you for showing me, but I couldn't see anyting solving my problem, I've even tried placing both "tokens(1)" and "Has connected" in an own array then joining them...
But I get the same result. I can place everything I want before "tokens(1)", but after that, nothing

Datanizze 0 Newbie Poster

There is "stuff" in every string, I just tried to make it simple because it is a part of a chat program.
The problem is that when the client sends something to the server, it needs to be split therefore the "dim tokens as string()"
however, when the server sends the data back to the client, and it gets split again. i.e the server sends "JOIN|user" the string gets split at "|" making the tokens(0) contain "CHAT" and tokens(1) contain "user".

So the "JOIN" command gets into a certain loop, where the tokens(1) is used to identify the new user, but when I try to get tokens(1) & "has joined the chat" I get the previously mentioned problem. It's a little complicated to explain, so I attached some code to maybe make it easier:

Dim buffer As Byte() = New Byte(2047) {}
'reads data from the server
           networkstream.Read(buffer, 0, buffer.Length)
'and converts it to a string
            Dim chatter As String = System.Text.Encoding.Unicode.GetString(buffer)
'declaring the "tokens" containing the two pieces "JOIN" and "user"
            Dim tokens As String() = chatter.Split("|")

 ' checks if the specified text in tokens(0) compares to any commands
            If tokens(0) = "JOIN" Then
'and if it does the text "user has connected" should be shown to the end user.
'But EVERYTHING after tokens(1) disappears so I'm left with only the user's name, and that won't make any sense when the end user only sees a name, and not knowing what's the meaning of it …
Datanizze 0 Newbie Poster

I have a strange problem, when I try to join two strings, one declared as a string()

dim string1 as string()

the string contains some data in both str(0) and str(1)
but when I try to add that with a regular string: "some text" like this:

dim string1 as string()
dim string2 as string

string2 = string1(1) & " Some text"

let's say string1(1) = "here is"

Which should result in: string2 = "here is Some text" BUT, all I get when the code execute is "here is not even a finishing "...
So where does: some text" go?
It's kind of crucial for my application to get the whole string since it provides needed data to continue! :S

happy for any thoughts and/or solutions :)

Datanizze 0 Newbie Poster

Hi! I'm having a problem with vb 2008 thinking my code is obsolete:

listener = New TcpListener(listenport)

So it wants an IP-address before the port:

'Public Sub New(port As Integer)' is obsolete: 'This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202'.

listener = New TcpListener(LocalAddr, listenport)

when Applying the new method I get rid of the complaining about obsolete code, but upon program start I don't get the popup about allowing the program through the firewall, rendering the program useless since it won't work outside the firewall's perimeters :(

The Question:
Is there a way of adding the program to the firewalls "allow-list" or to get the popup manually?
I can use the "old" code, but I like to keep everything up-to-date.