Pozdrav svima! radim chat program te zasad imam 2 problema
1. kad se client spoji na server nepokazuje mi kako spada userlistu
a kod koji imam sada je ovaj
server
For i = 0 To Winsock.Count - 1
For j = 0 To userslist.ListCount - 1
If Winsock(i).State = sckConnected Then
Winsock(i).SendData "LOGIN" & "|" & niz(1) & "|" & userslist.List(j) & "|" & txtNaziv.Text
End If
Next j
Next i
client
Case "LOGIN"
Userslist.AddItem niz(2)
2.
kad se spoji 1 korisnik na server(chat) sve je normalno no kad se spoji drugi korisnik na server on počne primat duple iste poruke,a treči opet kad se spoji dobije 3 iste poruke
kod za spajanje korisnika primanje konekcije(server)
Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Load Winsock(Winsock.UBound + 1)
' accept the incoming connection on our new control
Winsock(Winsock.UBound).Accept requestID
End Sub
kada na serveru dođe kod "connect"
Case "CONNECT"
userslist.AddItem (niz(1))
txthistory.Text = txthistory.Text & ("[" & Time & "] " & niz(1) & " was Login to Chat") & vbCrLf
For num = 0 To userslist.ListCount - 1
If userslist.List(num) = niz(1) Then
u = u + 1
End If
If u > 1 Then
userslist.RemoveItem (num)
For i = 0 To Winsock.Count - 1
If Winsock(i).State = 7 Then
Winsock(i).SendData "EXISTING" & "|" & niz(1)
DoEvents
End If
Next i
End If
Next num
For i = 0 To Winsock.Count - 1
For j = 0 To userslist.ListCount - 1
If Winsock(i).State = sckConnected Then
Winsock(i).SendData "LOGIN" & "|" & niz(1) & "|" & userslist.List(j) & "|" & txtNaziv.Text
End If
Next j
Next i
neznam dali treba al stavit ču kod od clienta recive data
rivate Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Dim niz() As String
Dim j As Integer
' Dobivanje podataka i prepoznavanje podataka
Winsock.GetData data
niz() = Split(data, "|")
Select Case niz(0)
' Logiranje na chat
Case "LOGIN"
Userslist.AddItem niz(2)
Timer.Interval = 500
Label2.Caption = "one"
'Otvaranje index fila i snimanje u njega.
Open App.Path & "/index.html" For Append As #1
Print #1, "<table cellspacing="; 0; " cellpadding="; 0; "><tr><td class='system'>[" & Time & "] Server: " & niz(1) & " has joined to the "; niz(3); " server!!!</td></tr></table>"
Close #1
txtHistory.Refresh
'Sviranje zvuka za novog korisnika
Dim newuser, variable As String
newuser = frmOptions.soundlist.ListItems(7).ListSubItems(1).Text
variable = sndPlaySound(newuser, 1)
'Kada dode poruka
Case "MESSAGE"
Open App.Path & "/index.html" For Append As #1
Print #1, "<table cellspacing="; 0; " cellpadding="; 0; "><tr><td class='system'><tr><td class='message'>[" & Time & "] " & niz(1) & ":" & niz(2) & "</td></tr></table>"
Close #1
txtHistory.Refresh
'Zvuk kad dode poruka
Dim message As String
message = frmOptions.soundlist.ListItems(1).ListSubItems(1).Text
variable = sndPlaySound(message, 1)
FlashWindow frmMain.hwnd, True
'Kad netko ode s chata
Case "DISCONNECT"
Open App.Path & "/index.html" For Append As #1
Print #1, "<table cellspacing="; 0; " cellpadding="; 0; "><tr><td class='system'>[" & Time & "] Server: " & niz(1) & " has logoff from the net!!!</td></tr></table>"
Close #1
txtHistory.Refresh
'Zvuk kad dode poruka
message = frmOptions.soundlist.ListItems(1).ListSubItems(1).Text
variable = sndPlaySound(message, 1)
FlashWindow frmMain.hwnd, True
' Postojeći korisnik
Case "EXISTING"
If niz(1) = frmOptions.txtNadimak.Text And Label2 = "one" Then
MsgBox "Username in use, chuse another nickname and then try to connect to server!", vbInformation
Winsock.Close
Userslist.Clear
cmdDisconnect.Enabled = False
cmdConnect.Enabled = True
frmOptions.opcije_frm.Enabled = True
frmMain.status.Panels.Item(1).Text = "You are dissconnected from: " & frmMain.Winsock.RemoteHost
End If
' Pogrešna lozinka
Case "ERROR"
If niz(1) = lozinka.Caption Then
MsgBox "Wrong Password!!!!", vbInformation, "Wrong Password", , "lol"
Winsock.Close
Userslist.Clear
cmdDisconnect.Enabled = False
cmdConnect.Enabled = True
frmOptions.opcije_frm.Enabled = True
frmMain.status.Panels.Item(1).Text = "You are dissconnected from: " & frmMain.Winsock.RemoteHost
End If
End Select
End Sub
e sjetio sam se i trečeg problema pošto koristim internet browser za prikazivanje poruka kako da napravim da kad mi dode zadnja poruka da mi prikaže nju a ne da mi vrati na početakbrowsera
hvala unaprijed molio bi ako znate da odgovorite na bilo koje pitanje odavde.
|