I have the client its in vb.net 8 i am using Microsoft Visual Studio 2005 it can connect and disconnect from the server join and leave the channel and can send text to the channel and it tells me what i say when i leave and join and connect and disconnect but i cant get it to get the text that everyone else says i used a tutorial and some of another guys source that he posted and i am wondering how i can make it get the data of what people say and have it output it to my status window i can send the source to someone if they need thank you and sry for not putting this into sentences i am kind of in a rush :P
edit: I am using winsocks and i thought this would work but it dosent
Code:
Dim data As String
Winsock1.GetData(data)
txtstatus.Text = txtstatus.Text & data & vbCrLf
Last edited by zillarat; Aug 26th, 2007 at 09:53 PM.
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData(data, vbString, bytesTotal)
txtstatus.Text = txtstatus.Text & data & vbCrLf
If InStr(data, "PING") = 1 Then
Winsock1.SendData("PONG " & Split(data, " ")(1))
End If
End Sub
ok i did it and there is nothing in the immediate window also no hits but i am connected because i can see my client nick and it can send text into the channel can i see it.
It wont get the data so i dont know what to do... :/
Last edited by zillarat; Aug 27th, 2007 at 04:45 AM.
How do you "see" the client nick?
Are "you" also a client?
When you send text to the "channel", where does it go (to the server, the a client..., is it recieved by anybody?)
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
The client i made connects to an IRC server but I also have the MIRC client connected to the same server in a channel I have that my IRC client I made will go in, when i connect the client i made and join the channel, i go to my MIRC client and i can see the client i made also i use the text box im the client i made and i can send messages to the channel and i can see them with both clients but when i send messages to the channel with mirc i cant see them in my client i made
So you can send messages using your VB-project, but you can't recieve messages, is that correct?
I don't know how those IRC and MIRC do send, maybe they use a kind of broadcast to send the messages recieved by the server to the connected clients?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
I think you are sending those messages to the server, and the server does retranmit them to the clients that are addressed (either all on the channel or a single one). That maybe a different winsock, and for that reason you don't get the messages. But I only think it is this reason, to know it is a differetn thing!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
so what do i have to do? I am looking through this and its like the sub Winsock1_DataArrival dosent exist or it dosent read it or something how can i make the priject know its there?
Last edited by zillarat; Aug 27th, 2007 at 04:50 PM.
If my assumption was correct (..that the server does send the messages on a different connection), your Winsock1 will NOT get any message, and the .DataArrival event will not fire at all!
To know that you have to look at what the server doing!!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
Opus so wouldent the server atleast send something or do i have to put a code in to tell the server to send me something?
Chris thanks for the code i dont see in it how the server send me anything i do everything in that and more alos i looked at the Winsock_DataArrival and i used some of that if thats ok but i cant even test it because my Winsock1_DataArrival dosent even get hit so first have to get that working :/
You don't have to tell the server to send you something. As soon as you connect to the IRC server it starts sending you information about the server.
Do you have "Option Explicit" at the top of your forms/modules/classes to check if you've made any mistakes? Maybe you've made a typo and without "Option Explicit" those small mistakes are hardly noticed.
::Edit::
And what port number are you using? Port number '6667' must be used or you won't be able to connect.
Last edited by Chris001; Aug 28th, 2007 at 09:06 PM.
yes i have it on i could just post the whole source if u guys want cuse im outa ideas on how to fix this, i cant find any errors, and all my friends that program program in c++ and they say learn c++
edit: yes its port 6667 i can connect to the server and talk in the channels i just cant receive anything.
Option Explicit On
Public Class main
Dim jchannel
Dim inick
Dim ihost
Dim iport
Private Sub txtsend_GotFocus()
End Sub
Private Sub connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connect.Click
inick = txtNick.Text
ihost = txtHost.Text
iport = txtPort.Text
Winsock1.Close()
Winsock1.RemotePort = iport
Winsock1.RemoteHost = ihost
Winsock1.Connect()
txtstatus.Text = txtstatus.Text & "Connected To " + ihost + "" & vbNewLine
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String, arrData() As String, i As Long
Dim arrWords() As String, arrParms() As String
Dim x As Long, y As Long, sName As String
Winsock1.GetData(strData)
txtstatus.Text = txtstatus.Text & strData & vbCrLf
'Seperate the different lines of data and parse through them
arrData = Split(strData, vbCrLf)
For i = 0 To UBound(arrData) - 1
arrWords = Split(arrData(i), " ")
arrParms = Split(arrData(i), ":")
'Get the seperate pieces of data that may be needed.
'Then Parse the data.
Select Case UCase$(arrWords(1))
Case "PRIVMSG"
'Get the name of the user who typed the message
x = InStr(arrParms(1), "!~")
If x Then
sName = Mid$(arrParms(1), 1, x - 1)
End If
txtstatus.Text = txtstatus.Text & "<" & sName & "> " & arrParms(2) & vbCrLf
Case Else
'Check for a PING and reply to it
If UCase$(arrWords(0)) = "PING" Then
Winsock1.SendData("PONG :" & arrParms(1) & vbCrLf)
End If
End Select
Next i
End Sub
Private Sub disconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles disconnect.Click
Winsock1.SendData("QUIT" & vbCrLf)
txtstatus.Text = txtstatus.Text & "Disconnected From " + ihost + "" & vbNewLine
Winsock1.Close()
End Sub
Private Sub join_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles join.Click
jchannel = txtJoin.Text
Winsock1.SendData("JOIN #" + jchannel & vbCrLf)
txtstatus.Text = txtstatus.Text & "Now Talking In " + jchannel + "" & vbNewLine
End Sub
Private Sub part_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles part.Click
jchannel = txtJoin.Text
Winsock1.SendData("PART #" + jchannel & vbCrLf)
txtstatus.Text = txtstatus.Text & "You Left " + jchannel + "" & vbNewLine
End Sub
Private Sub txtsend_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsend.TextChanged, sendbutton.TextChanged
End Sub
Private Sub Winsock1_ConnectEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Winsock1.ConnectEvent
Winsock1.SendData("NICK " + inick & vbCrLf)
Winsock1.SendData("USER " + inick + " " + inick + " " + inick + " " + inick + " " + inick & vbCrLf)
End Sub
Private Sub send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendbutton.Click
If Trim(txtsend.Text) = "" Then Exit Sub
Winsock1.SendData("PRIVMSG #" + jchannel + " :" + Trim(txtsend.Text) & vbCrLf)
txtstatus.Text = txtstatus.Text & "<" + inick + "> " + Trim(txtsend.Text) & vbNewLine
txtsend.Text = ""
txtsend.Focus()
End Sub
Private Sub txtNick_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNick.TextChanged
End Sub
Private Sub txtHost_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHost.TextChanged
End Sub
Private Sub txtPort_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPort.TextChanged
End Sub
Private Sub txtJoin_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJoin.TextChanged
End Sub
Private Sub txtstatus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtstatus.TextChanged
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Last edited by zillarat; Aug 28th, 2007 at 09:29 PM.
There are a few things to take into account. First of all, buffering: you might not always get a full line at once when you receive data, so you can only rely a full line is submitted if the last array element is empty (when you've splitted by line change). So, you need to keep the last array item in memory, and combine it to the first one:
So you might've been losing some information because of this.
The other thing is that you should look for the first " :" only and split on that to separate message content from commands and parameters. Then you can parse the commands and parameters by space character.
And third thing that comes to my mind is that you're relying on always receiving CRLF. However, some servers work a bit differently to the others and might use different line change:
Code:
' convert all possible line changes to vbLf
strData = Replace(strData, vbCrLf, vbLf)
strData = Replace(strData, vbCr, vbLf)
' ... or the same on one line:
strData = Replace(Replace(strData, vbCrLf, vbLf), vbCr, vbLf)
you can't just use a winsock like that in .NET , you should be using System.Net.Sockets.
however if you wish to receive data in the data_arrival sub, you need to specify bytes not a string ( eg: a byte array ) also replace any Long's with Integer's
so i'd try...
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Integer)
Dim bytesData(1024) As Byte
Winsock1.GetData(bytesData)
'/// get the data from the bytes() into a string ...
Dim strData As String = System.Text.Encoding.ASCII.GetString(bytesData, 0, bytesTotal)
'/// rest of your code here.
End Sub
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]