Results 1 to 11 of 11

Thread: [SOLVED] Whats wrong with this code ?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Resolved [SOLVED] Whats wrong with this code ?

    Code:
    Imports System.Threading
    Imports System.Net.Sockets
    Imports System.IO
    
    Module Module1
    Private Shared Sub Main(ByVal args As String()) 
        Console.ForegroundColor = ConsoleColor.Yellow 
        Console.WriteLine(ChrW(10) & "             -------- [ Packet Tester ] --------" & ChrW(10)) 
        Console.WriteLine("                   -------- [ Ver 1.0 ] --------") 
        Console.WriteLine("                     Original creator Walle") 
        Console.WriteLine("                  Need any help or having problems? Use the code, solve it :D" & ChrW(10)) 
        Console.WriteLine("             -------- [ Packet Tester ] --------" & ChrW(10)) 
        Console.ForegroundColor = ConsoleColor.Magenta 
        Console.Write("Website [URL/IP] : ") 
        Dim website As String = Console.ReadLine 
        Console.Write("Time [SECONDS] : ") 
        Dim s As String = Console.ReadLine 
        Console.Write(ChrW(10)) 
        Dim count As Integer = 1 
        Dim loop As Boolean = True 
        New Thread(Function 
            Dim start As ThreadStart = Nothing 
            Dim clients As New List(Of TcpClient)() 
            Do While [loop] 
                If (start Is Nothing) Then 
                    start = Function 
                        Dim item As New TcpClient() 
                        clients.Add(item) 
                        Try 
                            item.Connect(website, 80) 
                            Dim writer As New StreamWriter(item.GetStream) 
                            writer.Write(("POST / HTTP/1.1" & ChrW(13) & ChrW(10) & "Host: " & website & ChrW(13) & ChrW(10) & "Content-length: 5235" & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10))) 
                            writer.Flush 
                            If [loop] Then 
                                Console.ForegroundColor = ConsoleColor.Green 
                            End If 
                            Console.WriteLine(("Server Is Up / Packets sent: " & count)) 
                            count += 1 
                        Catch exception1 As Exception 
                            If [loop] Then 
                                Console.ForegroundColor = ConsoleColor.Red 
                            End If 
                            Console.WriteLine("Server Down!") 
                        End Try 
                    End Function 
                End If 
                New Thread(start).Start 
                Thread.Sleep(50) 
            Loop 
            Dim client As TcpClient 
            For Each client In clients 
                Try 
                    client.GetStream.Dispose 
                Catch exception1 As Exception 
                End Try 
            Next 
        End Function).Start 
        Thread.Sleep(CInt((Integer.Parse(s) * &H3E8))) 
        [loop] = False 
        Console.WriteLine(ChrW(10) & "Completed") 
        Console.WriteLine("Press any key to Close...") 
        Console.ReadKey 
    End Sub 
    End Module
    So i have the program exe file i used it for testing my server stability under "pressure". However i want to make some changes, and this is all the source code they posted on sourceforge. I know it's a VB.NET console application, so I make a new project in VS2013 as VB Console Application and then just insert the code into my module (e.g Module1). However, it shows a bunch of errors which i tried to fix, but I am just not that experience, so if anyone could help that would be awesome.
    Last edited by Edelweise; Mar 25th, 2016 at 09:40 PM.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Whats wrong with this code ?

    Hello,

    It would be a good idea to indicate what the exceptions are rather than saying there is a bunch of errors.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Re: Whats wrong with this code ?

    Well I though you guys can make a quick VB.NET console app, paste the code and see the errors, it would be easier, but okay i will show them.

    Code:
    Error	1	No accessible 'Main' method with an appropriate signature was found in 'ConsoleApplication3.Module1'.	ConsoleApplication3
    Error	2	Keyword is not valid as an identifier.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	21	9	ConsoleApplication3
    Error	3	Syntax error.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	22	5	ConsoleApplication3
    Error	4	'Do' must end with a matching 'Loop'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	25	9	ConsoleApplication3
    Error	5	'loop' is not declared. It may be inaccessible due to its protection level.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	25	18	ConsoleApplication3
    Error	6	'If' must end with a matching 'End If'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	26	13	ConsoleApplication3
    Error	7	'(' expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	27	32	ConsoleApplication3
    Error	8	'loop' is not declared. It may be inaccessible due to its protection level.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	35	24	ConsoleApplication3
    Error	9	'loop' is not declared. It may be inaccessible due to its protection level.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	41	24	ConsoleApplication3
    Error	10	'End If' must be preceded by a matching 'If'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	47	13	ConsoleApplication3
    Error	11	Syntax error.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	48	13	ConsoleApplication3
    Error	12	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	49	13	ConsoleApplication3
    Error	13	Statement cannot appear outside of a method body/multiline lambda.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	50	9	ConsoleApplication3
    Error	14	Statement cannot appear outside of a method body/multiline lambda.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	52	9	ConsoleApplication3
    Error	15	Statement cannot appear outside of a method body/multiline lambda.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	53	13	ConsoleApplication3
    Error	16	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	54	17	ConsoleApplication3
    Error	17	Statement cannot appear outside of a method body/multiline lambda.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	55	13	ConsoleApplication3
    Error	18	'End Try' must be preceded by a matching 'Try'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	56	13	ConsoleApplication3
    Error	19	Syntax error.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	57	9	ConsoleApplication3
    Error	20	'End Function' must be preceded by a matching 'Function'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	58	5	ConsoleApplication3
    Error	21	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	59	5	ConsoleApplication3
    Error	22	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	60	5	ConsoleApplication3
    Error	23	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	61	5	ConsoleApplication3
    Error	24	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	62	5	ConsoleApplication3
    Error	25	Declaration expected.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	63	5	ConsoleApplication3
    Error	26	'End Sub' must be preceded by a matching 'Sub'.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication3\ConsoleApplication3\Module1.vb	64	1	ConsoleApplication3

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Whats wrong with this code ?

    Did you just paste that code into the module? Or did your first clear out all of the pre-existing code from the module first?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Whats wrong with this code ?

    OH.... I see now... it's using a multi-line anonymous function.... starts with this line:

    hmmm..... it seems to have a number of issues... where exactly did you get this from?

    I keep going around in circles trying to get it to work...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Re: Whats wrong with this code ?

    Quote Originally Posted by techgnome View Post
    OH.... I see now... it's using a multi-line anonymous function.... starts with this line:

    hmmm..... it seems to have a number of issues... where exactly did you get this from?

    I keep going around in circles trying to get it to work...

    -tg
    I am trying to make it work too for the whole day. Originally the source code comes from sourceforge, but this current one is from my friend, cause it's an old project and it doesn't exist on sourceforge anymore or at last i couldn't find it, so he sended it He said it's the original code he downloaded from sourceforge. He didn't changed it or anything.
    Last edited by Edelweise; Mar 25th, 2016 at 09:20 AM.

  7. #7
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Whats wrong with this code ?

    When you grab some code, you should really go through it lime by line and look up features that you do not know.

    I only glanced at your code, but I see that the variable start is declared as a System.Threading.ThreadStart Delegate. Look at the signature for that delegate (if you do not understand delegates, research them). It is a delegate for a method that does not return a value, yet the code is attempting to assign an anonymous function to it. Set Option Strict On. Also the first line of that assignment has a syntax error in that its missing the "()" after the erroneous usage of Function .
    Code:
    start = Function 
         ' your code
    End Function
    should be
    Code:
    start = Sub()
         ' your code
    End Sub
    I didn't go any further in my review. Try making that correction and see what happens.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Re: Whats wrong with this code ?

    @TnTinMN used your code, worked fine. I fixed some of the errors. Also, the last few lines after Next:

    Code:
        End Function).Start 
        Thread.Sleep(CInt((Integer.Parse(s) * &H3E8))) 
        [loop] = False 
        Console.WriteLine(ChrW(10) & "Completed") 
        Console.WriteLine("Press any key to Close...") 
        Console.ReadKey
    Can be removed. It's all about some message and stop the tool if it crash the server, that i'll probably live without it. So now i have the code like so:

    Code:
    Imports System.Threading
    Imports System.Net.Sockets
    Imports System.IO
    
    Module Module1
    
        Dim [loop] As Boolean = True
    
        Private Sub Main(ByVal args As String())
            Console.ForegroundColor = ConsoleColor.Yellow
            Console.WriteLine(ChrW(10) & "             -------- [ Packet Tester ] --------" & ChrW(10))
            Console.WriteLine("                   -------- [ Ver 1.0 ] --------")
            Console.WriteLine("                     Original creator Walle")
            Console.WriteLine("                  Need any help or having problems? Use the code, solve it :D" & ChrW(10))
            Console.WriteLine("             -------- [ Packet Tester ] --------" & ChrW(10))
            Console.ForegroundColor = ConsoleColor.Magenta
            Console.Write("Website [URL/IP] : ")
            Dim website As String = Console.ReadLine
            Console.Write("Time [SECONDS] : ")
            Dim s As String = Console.ReadLine
            Console.Write(ChrW(10))
            Dim count As Integer = 1
        New Thread(Function 
            Dim start As ThreadStart = Nothing
            Dim clients As New List(Of TcpClient)()
            Do While [loop]
                If (start Is Nothing) Then
                    start = Sub()
                                Dim item As New TcpClient()
                                clients.Add(item)
                                Try
                                    item.Connect(website, 80)
                                    Dim writer As New StreamWriter(item.GetStream)
                                    writer.Write(("POST / HTTP/1.1" & ChrW(13) & ChrW(10) & "Host: " & website & ChrW(13) & ChrW(10) & "Content-length: 5235" & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10)))
                                    writer.Flush()
                                    If [loop] Then
                                        Console.ForegroundColor = ConsoleColor.Green
                                    End If
                                    Console.WriteLine(("Server Is Up / Packets sent: " & count))
                                    count += 1
                                Catch exception1 As Exception
                                    If [loop] Then
                                        Console.ForegroundColor = ConsoleColor.Red
                                    End If
                                    Console.WriteLine("Server Down!")
                                End Try
                            End Sub
                End If
                New Thread(start).Start 
                Thread.Sleep(50)
            Loop
            Dim client As TcpClient
            For Each client In clients
                Try
                    client.GetStream.Dispose()
                Catch exception1 As Exception
                End Try
            Next
        End Sub
    End Module
    With just 3 errors:

    Code:
    Error	1	No accessible 'Main' method with an appropriate signature was found in 'ConsoleApplication4.Module1'.	ConsoleApplication4
    Error	2	Syntax error.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication4\ConsoleApplication4\Module1.vb	23	5	ConsoleApplication4
    Error	3	Syntax error.	c:\users\darkcon\documents\visual studio 2013\Projects\ConsoleApplication4\ConsoleApplication4\Module1.vb	49	13	ConsoleApplication4
    Name:  28d9e38e315d9fae7d758561aaf4f7f6.png
Views: 2195
Size:  3.7 KB Name:  c173ed6644e489c7ecdfc3e6accc2499.png
Views: 2196
Size:  2.6 KB

    We're almost there
    Last edited by Edelweise; Mar 25th, 2016 at 06:34 PM.

  9. #9
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Whats wrong with this code ?

    The remaining syntax errors can be fixed with the following changes. Whether or not the code itself is valid, I make no such assurances.
    Code:
    	 Friend Sub Main(ByVal args As String())
    		  Console.ForegroundColor = ConsoleColor.Yellow
    		  Console.WriteLine(ChrW(10) & "             -------- [ Packet Tester ] --------" & ChrW(10))
    		  Console.WriteLine("                   -------- [ Ver 1.0 ] --------")
    		  Console.WriteLine("                     Original creator Walle")
    		  Console.WriteLine("                  Need any help or having problems? Use the code, solve it :D" & ChrW(10))
    		  Console.WriteLine("             -------- [ Packet Tester ] --------" & ChrW(10))
    		  Console.ForegroundColor = ConsoleColor.Magenta
    		  Console.Write("Website [URL/IP] : ")
    		  Dim website As String = Console.ReadLine
    		  Console.Write("Time [SECONDS] : ")
    		  Dim s As String = Console.ReadLine
    		  Console.Write(ChrW(10))
    		  Dim count As Integer = 1
    		  Dim t1 As New Thread(Sub()
    
    			  Dim start As ThreadStart = Nothing
    			  Dim clients As New List(Of TcpClient)()
    			  Do While [loop]
    					If (start Is Nothing) Then
    						 start = Sub()
    										 Dim item As New TcpClient()
    										 clients.Add(item)
    										 Try
    											  item.Connect(website, 80)
    											  Dim writer As New StreamWriter(item.GetStream)
    											  writer.Write(("POST / HTTP/1.1" & ChrW(13) & ChrW(10) & "Host: " & website & ChrW(13) & ChrW(10) & "Content-length: 5235" & ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10)))
    											  writer.Flush()
    											  If [loop] Then
    													Console.ForegroundColor = ConsoleColor.Green
    											  End If
    											  Console.WriteLine(("Server Is Up / Packets sent: " & count))
    											  count += 1
    										 Catch exception1 As Exception
    											  If [loop] Then
    													Console.ForegroundColor = ConsoleColor.Red
    											  End If
    											  Console.WriteLine("Server Down!")
    										 End Try
    									End Sub
    					End If
    					Dim t2 As New Thread(start)
    					t2.Start()
    					Thread.Sleep(50)
    			  Loop
    			  Dim client As TcpClient
    			  For Each client In clients
    					Try
    						 client.GetStream.Dispose()
    					Catch exception1 As Exception
    					End Try
    			  Next
    
    		 End Sub)
    
    		 t1.Start()
    
    	 End Sub

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Re: Whats wrong with this code ?

    @TnTinMN Thank you very much. My code is working now. THANKS!
    Last edited by Edelweise; Mar 25th, 2016 at 09:39 PM.

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2016
    Posts
    47

    Re: [SOLVED] Whats wrong with this code ?

    Btw @TnTinMN can you try make it work with the code i said it's not needed ? Cause actually, it is needed.
    Code:
        End Function).Start 
        Thread.Sleep(CInt((Integer.Parse(s) * &H3E8))) 
        [loop] = False 
        Console.WriteLine(ChrW(10) & "Completed") 
        Console.WriteLine("Press any key to Close...") 
        Console.ReadKey
    Thanks!

    EDIT: I've make it to work.
    Last edited by Edelweise; Mar 26th, 2016 at 12:21 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width