Solved

how to fix problem, cant call class

Posted on 2006-11-11
5
199 Views
Last Modified: 2010-04-23
im trying to use the below call i made a class file clas1.vb pasted the below code
now im trying to make it work

1: how do i call the call im trying

            AsynchSockets.Client.Main("")

and im getting an error of
Error      1      Value of type 'String' cannot be converted to '1-dimensional array of String'.      C:\Documents and Settings\Pern\My Documents\Visual Studio 2005\Projects\ircd stress\ircd stress\Form1.vb      34      39      ircd stress

2: how do i pass the host and message args if i can get this to work


' client.vb
'
' Simple socket client that sends a string to the server
' and reads the response.
'
' Mike Woodring
' http://staff.develop.com/woodring
'
Imports System
Imports System.Net.Sockets
Imports System.Threading
Imports System.Runtime.Serialization.Formatters.Binary

Namespace AsynchSockets
    Public Class Client
        ' Command line:
        '      client hostname string_to_send
        '
        Public Shared Function Main(ByVal Args() As String) As Integer
            Dim HostName As String = "localhost"
            Dim Msg As String = "Hello, .NET sockets."

            If Args.Length >= 1 Then
                HostName = Args(0)
            End If

            If Args.Length >= 2 Then
                Msg = Args(1)
            End If

            Dim c As New Client(HostName)
            Return c._Main(Msg)

        End Function 'Main


        Sub New(ByVal HostName As String)
            Console.WriteLine("Connecting to {0}", HostName)
            tcpSocket = New TcpClient(HostName, 6667)
            streamToServer = tcpSocket.GetStream()

        End Sub 'New


        Private Function GetCurrentThreadId() As Integer
            Return Thread.CurrentThread.GetHashCode()

        End Function 'GetCurrentThreadId


        Private Function _Main(ByVal Msg As String) As Integer
            Console.WriteLine("Sending {0} to server.", Msg)

            ' Send a string (newline terminated) to the server.
            '
            Dim writer As New System.IO.StreamWriter(streamToServer)
            writer.WriteLine(Msg)
            writer.Flush()

            ' Read server response (up to a newline).
            '
            Dim reader As New System.IO.StreamReader(streamToServer)
            Dim strResponse As String = reader.ReadLine()
            Console.WriteLine("Received: {0}", strResponse)

            streamToServer.Close()
            Return 0

        End Function '_Main

        Private tcpSocket As TcpClient
        Private streamToServer As NetworkStream
    End Class 'Client
End Namespace
0
Comment
Question by:Johnny
  • 3
5 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17921120
Your trying to pass a string into an array.

Try : AsynchSockets.Client.Main(Nothing)
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17921126
or

        Dim arr() As String = {"Host", "Message Here"}
        Main(arr)
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17921132
sorry, should be: AsynchSockets.Client.Main(arr)
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17921143
or simply AsynchSockets.Client.Main(Split("Host,message",","))
0
 

Author Comment

by:Johnny
ID: 17921162
sorry nightman did refresh...other seams to work

altho the code to connect does not seam to work...grumble

a simple connection to irc and return the reply ....why is this so dang hard...grrrr (like the 5th code example ive tried no joy here)

thanks for the replies
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now