Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

trying to get simple connection to irc

im trying to send a logon string to a irc server and capture the return how do i do this

ive been trying with the below code but it does not work...

            Connect(txtServer.Text, txtPort.Text, "NICK " & txtBaseNick.Text & Index & vbLf & "USER TEST tst text :text" & Index & vbLf & "PONG :mkv" & vbLf & "JOIN " & txtChannel.Text & vbLf)


   Sub Connect(ByVal server As [String], ByVal irc_port As Int32, ByVal message As [String])
        Try
            ' Create a TcpClient.
            ' Note, for this client to work you need to have a TcpServer
            ' connected to the same address as specified by the server, port
            ' combination.
            Dim port As Int32 = irc_port
            Dim client As New TcpClient(server, port)

            ' Translate the passed message into ASCII and store it as a Byte array.
            Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

            ' Get a client stream for reading and writing.
            '  Stream stream = client.GetStream();
            Dim stream As NetworkStream = client.GetStream()

            ' Send the message to the connected TcpServer.
            stream.Write(data, 0, data.Length)

            Console.WriteLine("Sent: {0}", message)
            Form1.ListBox1.Items.Add("Sent: " & message)
            'My.Application.DoEvents()
            ' Receive the TcpServer.response.
            ' Buffer to store the response bytes.
            data = New [Byte](256) {}

            ' String to store the response ASCII representation.
            Dim responseData As [String] = [String].Empty

            ' Read the first batch of the TcpServer response bytes.
            Dim bytes As Int32 = stream.Read(data, 0, data.Length)
            responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
            Console.WriteLine("Received: {0}", responseData)
            Form1.ListBox2.Items.Add("Received: " & responseData)
            'My.Application.DoEvents()
            ' Close everything.
            stream.Close()
            client.Close()
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: {0}", e)
        Catch e As SocketException
            Console.WriteLine("SocketException: {0}", e)
        End Try

        'Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
        'Console.Read()
    End Sub 'Connect
Avatar of Nightman
Nightman
Flag of Australia image

What error do you get, and where?
ASKER CERTIFIED SOLUTION
Avatar of Mohamed Zedan
Mohamed Zedan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or you could use it's compiled dll in your vb.net application without converting it :)
if that code, works he can even add the whole C# code as a separate project on his VB application and it would work too.
Avatar of Johnny

ASKER

im not getting a full connection..it send the info, and gets back the info

maybe im missing the logon itself.. besides what im sending to login to join a room

Perhaps you could give the library from mohzedan a try. It also looks to be well documented, with some examples as well.
Avatar of Johnny

ASKER

went with the smart irc code.... having problems converting it

hopefully it will be ok tho

thanks for the help on to converting it questions
https://www.experts-exchange.com/questions/22057410/convert-c-to-vb-net-please.html
You don't need to convert it. ... you should just build the project and add the dll as a reference to your project and use it as is
Avatar of Johnny

ASKER

theres no vb.net example code so to have c code converted it all there is...


i did most of it..and have it connecting...im trying to show the sends and the replies now..then ill be ok having problems with that..i was gonna open another question sometime for ask how to do that..if i cnat figure it out soon
why don't you post the c# example code here and I'll convert it for you ?