Trying to at least set up connection

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
Hi,

I'm trying to make an admin console/bot for my own IRC server, but I can't figure out how to get this to connect to my server. I need to connect to my local IP address (192.168.1.97). I tried some other things, but I couldn't figure out how to convert that IP to a long IP. I found that the TCPClient class can use the hostname as an argument, so I'm trying to use the hostname of my computer (Dorothy). Could someone please look at this and tell me what's wrong? It finally loads the form without errors, but I'm not so sure it's connecting. I'll also need help with how to send commands to the server once I figure this out. Thanks. Here's the code
VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Client [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Net.Sockets.TcpClient()
Client.Connect([/SIZE][SIZE=2][COLOR=#800000]"Dorothy"[/COLOR][/SIZE][SIZE=2], 6667)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Stream [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Net.Sockets.NetworkStream = Client.GetStream
Sock_Connect()
[/SIZE][SIZE=2][COLOR=#008000]'Stream.Write("NICK " & "VB_Bot" & vbCrLf)
[/COLOR][/SIZE][SIZE=2]Client.GetStream()
[/SIZE][SIZE=2][COLOR=#008000]'Client.Send("NICK " & "VB_Bot" & vbCrLf)
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'Client.Send("USER " & "VB_Bot" & " " & "Dorothy" & " " & _
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'UCase("Dorothy" & ":" & 1903 & "/0") & " :" & "VB_Bot" & vbCrLf)
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Sock_Connect()
MessageBox.Show([/SIZE][SIZE=2][COLOR=#800000]"Connected"[/COLOR][/SIZE][SIZE=2])

[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
You can ignore all the commented lines. I was just testing some things.
 
Here is some short help example code to work the TcpClient (and TcpListener) http://www.eggheadcafe.com/articles/20020323.asp

About the IP, "Dorothy" must be a valid DNS/WINS host name on the network (not just a machine name), "localhost" should work, also IPAddress.Parse("127.0.0.1")
 
Thanks, that did help some. I'm at least establishing a connection now. The Messagebox.Show is showing me that my server is saying "*** Found your hostname". That's as far as it gets though, and I don't know how to fix it.
I need to fix something with replying to server pings before I get any further. For the first time the server pings me, I need to respond with a certain code that it gives. The code changes every time I connect, so I can't just hard code that value in. If the server sends "PING :82DA0945", I need to reply with "PONG :82DA0945". How would I code that to get that value from what it sends so I can send it back? After that, I also need it so that everytime the server pings, I respond with "pong", so I don't timeout. Thanks for any help. This is what I have so far, although the joining channels isn't working.
VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tcpClient [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Net.Sockets.TcpClient()
tcpClient.Connect([/SIZE][SIZE=2][COLOR=#800000]"127.0.0.1"[/COLOR][/SIZE][SIZE=2], 6667)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] networkStream [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] NetworkStream = tcpClient.GetStream()
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] networkStream.CanWrite [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] networkStream.CanRead [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Do a simple write.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sendBytes [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes([/SIZE][SIZE=2][COLOR=#800000]"NICK VB_Bot"[/COLOR][/SIZE][SIZE=2])
networkStream.Write(sendBytes, 0, sendBytes.Length)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Nick [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"VB_Bot"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] MyNick [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(Nick)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] UserData [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"USER VB-Bot Dorothy 192.168.1.97 :me"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] MyUser [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(UserData)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Pong [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"PONG :braab.myftp.org"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] PongSend [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(Pong)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Identify [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"PRIVMSG nickserv :identify 1qazxsw2"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] IdentifySend [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(Identify)
networkStream.Write(MyNick, 0, MyNick.Length)
networkStream.Write(MyUser, 0, MyUser.Length)
[/SIZE][SIZE=2][COLOR=#008000]'networkStream.Write(IdentifySend, 0, IdentifySend.Length)
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Read the NetworkStream into a byte buffer.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bytes(tcpClient.ReceiveBufferSize) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte
[/COLOR][/SIZE][SIZE=2]networkStream.Read(bytes, 0, [/SIZE][SIZE=2][COLOR=#0000ff]CInt[/COLOR][/SIZE][SIZE=2](tcpClient.ReceiveBufferSize))
[/SIZE][SIZE=2][COLOR=#008000]' Output the data received from the host to the console.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] returndata [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Encoding.ASCII.GetString(bytes)
MessageBox.Show(([/SIZE][SIZE=2][COLOR=#800000]"Host returned: "[/COLOR][/SIZE][SIZE=2] + returndata))
networkStream.Write(PongSend, 0, PongSend.Length)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Join [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"braab.myftp.org JOIN #chat"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] JoinSend [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(Join)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ChatMode [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"MODE #chat"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ChatModeSend [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(ChatMode)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ChatWho [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"WHO #chat"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ChatWhoSend [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [Byte]() = Encoding.ASCII.GetBytes(ChatWho)
networkStream.Write(JoinSend, 0, JoinSend.Length)
networkStream.Write(ChatModeSend, 0, ChatModeSend.Length)
networkStream.Write(ChatWhoSend, 0, ChatWhoSend.Length)
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] networkStream.CanRead [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"cannot not write data to this stream"[/COLOR][/SIZE][SIZE=2])
tcpClient.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] networkStream.CanWrite [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"cannot read data from this stream"[/COLOR][/SIZE][SIZE=2])
tcpClient.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' pause so user can view the console output
[/COLOR][/SIZE][SIZE=2]Console.ReadLine()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
Is this closing the connection? I have a question in to the mIRC boards to make sure that I'm using the right format for what I'm sending. I know at least one problem is that it eventually pings out because I'm not sending the pong with that code.
 
Last edited:
Getting some part out of a string? Have a look at the String class, you have a lot of string tools at your disposal. String manipulation is very important in programming, you should read and test out all the members of this class. http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemStringClassTopic.asp

Also, here is the info about the Close method of TcpClient (yes it closes connection) http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetSocketsTcpClientClassCloseTopic.asp
 
Thanks for those links. I wasn't sure what the two integers were that were used, but I'll look at it some more. Will I need some kind of loop to keep this connection alive and keep listening for data on the network stream? I'll also need a line for if the data has "PONG" in it, so I can respond. I guess that will be using the string, so I can basically say "if the first word is PING....". Thanks again.
 
You can use a Timer and check if DataAvailable for the networkstream.
 
Thanks, I'll have to look into timers. I think I figured out how to use Split, but I cant figure out how to compare the second item once it's split. I have a line like this, but it's giving me errors:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pongtest [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Encoding.ASCII.GetString(bytes)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Split([pongtest], [/SIZE][SIZE=2][COLOR=#800000]" "[/COLOR][/SIZE][SIZE=2], 2) = [/SIZE][SIZE=2][COLOR=#800000]"PING"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
So you haven't got time to look a the String class yet? String class got a Split method that returns the different items as a string array.

dim input as string = "ping :21908"
dim inputs() as string = input.split(" ")

inputs(0) is now "ping"
inputs(1) is now ":21908"
 
Wow, thanks. I must have missed that part. Sorry for all of my questions. I was in the hospital recently, and I'm taking some painkillers that really slow me down, which is frustrating. I'll have to try that out and see if I can fix the ping problem. Thank you very much!
 
I'm not even sure what this program is doing anymore, or how to deal with these pings. The stuff that I get from the server when I connect through mIRC are these two lines:

*** If you are having problems connecting due to ping timeouts, please type /quote pong 22ED7AF8 or /raw pong 22ED7AF8 now.

PING :22ED7AF8

When I step debug, it freezes at one step so long that it times out before I can see if putting two reads gets me what I want.
My VB program keeps timing out of the server, and I'm still not sure how to handle the pings. Maybe I need to give this a break for awhile. My mind just isn't grasping this.
 
I just had one more idea to try in a desperate attempt to get this to work. Like I said, I'm going to give it a break for awhile, but something I did today gave me an idea. I can't think of any real difference this could make offhand, but would it be better if I included a TCPListener? I'm going to try my ideas tomorrow just for a bit to see what I come up with. Thanks.
 
If you want to create an IRC server then TcpListener is a good idea.

About the ping, it's really easy, once connected you just keep listening for instance with a timer, check if networkstream.dataavailable, if so read it, if it is a ping ("PING :22ED7AF8") then immediately return pong ("PONG :22ED7AF8")
 
I wasn't sure how to put the TCPListener in when I have a TCPClient as well. How would I tell it what port to listen to. I'd be connecting to the server on port 6667, but the port it comes back on could be anything, right? I've decided to start this over from the beginning, but my form isn't doing anything. Can you look at this and tell me why. I'd think that when I step debug, it should at least hit the Form1_load line and highlight it in yellow, but it isn't doing that.
VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Text
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Net
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Net.Sockets
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button14_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button14.Click
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
TextBox6.Text = [/SIZE][SIZE=2][COLOR=#800000]"VB_Bot"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Server [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] TcpClient
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] data() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2](1024) {}
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strData [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Nick [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"NICK VB_Bot"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] User [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"USER VB_Bot Dorothy braab.myftp.org VB_Bot"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] PongReply [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"PONG "
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]Server = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] TcpClient([/SIZE][SIZE=2][COLOR=#800000]"192.168.1.97"[/COLOR][/SIZE][SIZE=2], 6667)
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ns [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] NetworkStream = Server.GetStream
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Receive [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2]Receive = ns.Read(data, 0, data.Length)
strData = Encoding.ASCII.GetString(data, 0, Receive)
data = Encoding.ASCII.GetBytes(Nick.ToCharArray)
ns.Write(data, 0, data.Length)
data = Encoding.ASCII.GetBytes(User.ToCharArray)
ns.Write(data, 0, data.Length)
MessageBox.Show(strData)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
 
I don't think you understood what I meant last post. Stay away from the TcpListener, ok? understood? fine.
 
I have finally got around to test this IRC stuff myself, the project is attached as zip file. I made some discoveries, first server tested on the EFnet network gave same timeout errors as you describe. Only messages I got was trying to reach identd and Ping timeout. So I included a Identd-server in the app (for this a TcpListener was needed!), but same timeout. Then I tried a IRCnet network server with immediate success. This server also worked without the Identd-server, but I left it in project in case anybody needs it.

The project is perfect for this thread question, "Trying to at least set up connection", you can: connect/disconnect server, join/part channel, read the output of all messages received, send messages to channel, and includes a simple example of both channel and private IrcBot command.

Quite a lot of work is needed to make it 'nice' with good dialogs, specific messages handling, routing messages to the right server/channel/private window, easy to read text formatting, adding useful Bot commands, error handling etc. I leaves all this to you :)

To try things out, find a network/server that will connect (example server did). Use a regular IRC client like mIRC and join a new channel, just make up some strange channel name so you can be left in peace to debug/test. Join with this client app too and test out by interacting with the regular client and reading the server messages.
 

Attachments

  • vbnet20-IrcBot.zip
    15.5 KB · Views: 44
Back
Top