Chat Server Help!
Chat Server Help!
Chat Server Help!
Chat Server Help!
Chat Server Help!
Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help!
Chat Server Help! Chat Server Help!
Chat Server Help!
Go Back  Xtreme Visual Basic Talk > > > Chat Server Help!


Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2004, 01:42 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Chat Server Help!


I made a Chat Client and Server. I want to be able to boot people off from the server without shutting the server down or without booting everyone off. Any ideas how I can do that?
Reply With Quote
  #2  
Old 02-26-2004, 02:17 PM
GavinO's Avatar
GavinOChat Server Help! GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

Just close the connection. It is generally a better idea to have the boot part written into the protocol though, so you can send a 'i'm booting you' message to the client, allowing for a clean disconnect.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #3  
Old 02-26-2004, 02:31 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

Here is the code for my Chat Server:
---------------------------------------------

Code:
Dim Amount As Integer Private Sub SendConnects() Dim msg As String For i = 0 To List.ListCount - 1 msg = msg & List.List(i) & "|" Next i For i = 1 To Amount If sock(i).State = sckConnected Then sock(i).SendData "cons|" & msg: DoEvents Next i End Sub Private Sub SetList() List.Clear For i = 1 To Amount If sock(i).State = sckConnected Then List.AddItem sock(i).Tag Next i End Sub Private Sub Form_Load() sock(0).LocalPort = 8765 sock(0).Listen End Sub Private Sub sock_Close(Index As Integer) sock(Index).Tag = "" SetList SendConnects End Sub Private Sub sock_ConnectionRequest(Index As Integer, ByVal requestID As Long) Amount = Amount + 1 Load sock(Amount) sock(Amount).Accept requestID End Sub Private Sub sock_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim GetIt As String sock(Index).GetData GetIt msg = Split(GetIt, "|") Select Case msg(0) Case "name" sock(Index).Tag = msg(1) SetList SendConnects Case "text" For i = 1 To Amount If sock(i).State = sckConnected And Not i = Index Then sock(i).SendData "text|" & _ sock(Index).Tag & "|" & msg(1): DoEvents Next i End Select End Sub

From the code above, how would I make a boot part written into the protocol?

Last edited by PlenoJure; 02-27-2004 at 08:42 AM. Reason: Added [vb] tags
Reply With Quote
  #4  
Old 02-27-2004, 08:40 AM
GavinO's Avatar
GavinOChat Server Help! GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

I can't really see your protocol in what you have above. What it would look like is just another command that you send to the client. You usually prefix messages with something to indicate what the rest of the message is, be it a chat message, a request for a username/password, etc. You'd just add a message type for 'boot', the body of the message might be a reason or whatnot.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #5  
Old 02-27-2004, 12:24 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I'm still having problems. Here is the code for the Chat Client

Code:
Private Sub Title(What As String) Me.Caption = "Chat [" & What & "]" End Sub Private Sub AddText(Who, WhatText) txtChat.Text = txtChat.Text & "-=" & Who & "=-" & vbCrLf txtChat.Text = txtChat.Text & WhatText & vbCrLf txtChat.SelStart = Len(txtChat.Text) End Sub Private Sub con_Click() Dim Server As String Server = InputBox("Please write IP or HostName.", "Connect", "LocalHost") sock.Close sock.Connect Server, 8765 End Sub Private Sub Form_Load() Title "Disconnected" End Sub Private Sub mnuQuit_Click() End End Sub Private Sub sock_Close() Title "Disconnected" End Sub Private Sub sock_Connect() Dim msg As String Title "Connected" DoEvents msg = "name|" & txtName.Text sock.SendData msg End Sub Private Sub sock_DataArrival(ByVal bytesTotal As Long) Dim GetIt As String sock.GetData GetIt msg = Split(GetIt, "|") Select Case msg(0) Case "cons" List.Clear For i = 1 To UBound(msg) - 1 List.AddItem msg(i) Next i Case "text" AddText msg(1), msg(2) End Select End Sub Private Sub txtOut_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then AddText txtName.Text, txtOut.Text sock.SendData "text|" & txtOut.Text txtOut.Text = "" End If End Sub

When I run my server, all it shows is just a list of people that are logged into the server. I want to be able to click on any user and boot them. Can you explain how to do that in a better way.
Reply With Quote
  #6  
Old 02-27-2004, 01:21 PM
GavinO's Avatar
GavinOChat Server Help! GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

Looking at the code, it seems that your protcol delimits the command from the message with a pipe. This is good. Just add a handler on message receipt to check for a command of 'boot', and act appropriately (close connection, inform the user).
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #7  
Old 02-27-2004, 04:29 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I am kinda new to this stuff but I understand what your talking about. It's just well, where do I add a handler? Thanks for respondin to this.
Reply With Quote
  #8  
Old 02-28-2004, 06:42 PM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

in your code here...
Code:
Select Case msg(0) Case "cons" List.Clear For i = 1 To UBound(msg) - 1 List.AddItem msg(i) Next i Case "text" AddText msg(1), msg(2)


add ..

Code:
Case "boot" sock.close AddText "You have been booted"


or some message like that
Reply With Quote
  #9  
Old 02-28-2004, 11:21 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

Ok, I added that but when I went to compile it, I got an error saying "Argument Not Optional" and it has AddText highlighted. Couldn't I just changed the AddText to MsgBox?

There is one thing I dont understand. If I add that code to the Client...How will the server be able to boot them? Or How will I be able to boot the user?
Reply With Quote
  #10  
Old 02-29-2004, 11:36 AM
GavinO's Avatar
GavinOChat Server Help! GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

The idea is that the client will close the connection itself when you tell it to. You could reinforce this by having the server close the connection as well, however.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #11  
Old 02-29-2004, 08:47 PM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

Quote:
Originally Posted by Timot
Ok, I added that but when I went to compile it, I got an error saying "Argument Not Optional" and it has AddText highlighted. Couldn't I just changed the AddText to MsgBox?

There is one thing I dont understand. If I add that code to the Client...How will the server be able to boot them? Or How will I be able to boot the user?




well, for the addtext, put

Code:
addtext "System Message","You have been booted!"

or, yeah, you could use a message box..


if you use a listbox for the users that log in, then when you add the user, you could make the listdata for that user the winsock index. use this for the SetList() sub:

Code:
Private Sub SetList() List.Clear For i = 1 To Amount If sock(i).State = sckConnected Then List.AddItem sock(i).Tag List.ItemData(List.listcount -1) = i End If Next i End Sub


to boot from the server, just send a message like you would normally send a message... just maybe put a Boot button and make it send the command:

Code:
Private Sub cmdBoot_Click() sock(List.ItemData(List.ListIndex).senddata "boot|boot" DoEvents sock(List.ItemData(List.ListIndex).Close List.RemoveItem(List.ListIndex) End Sub



if you do that, then you could make it so that when you click on a name in the list and then press the Boot command button, it will close the connection to that person only..


i didn't test this.. but i'm pretty sure it will work.. hope it helps
Reply With Quote
  #12  
Old 02-29-2004, 10:17 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I entered the code and everything. I keep getting some compile errors.

Private Sub cmdBoot_Click()
sock(List.ItemData(List.ListIndex).senddata "boot|boot"
DoEvents
sock(List.ItemData(List.ListIndex).Close
List.RemoveItem(List.ListIndex)
End

Visual Basic highlights (in red) the two lines that start with sock. I think I fixed it when I added another () after (List.ItemData) But I ran into another compile error which highlights .itemdata and says Argument Not Optional.

I took out the (list.itemdata) out of both lines since it said it was optional and it compiled correctly. When I went to test the boot out I got another error. Run-Time Error: Wrong Protocol or connection state for the requested transaction or request. I tried to boot myself out of my server, that might be the problem but I don't think it is.

I appreciate the help.
Reply With Quote
  #13  
Old 03-01-2004, 06:35 AM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

Code:
Private Sub SetList() List.Clear For i = 1 To Amount If sock(i).State = sckConnected Then List.AddItem sock(i).Tag List.ItemData(List.ListCount -1) = i End If Next i End Sub

did you add this part in?
Reply With Quote
  #14  
Old 03-01-2004, 10:37 AM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I still getting some errors, most of them I am figuring out myself. I ran into a small problem. When I go to boot the user, it shows the message (You have been booted) on my computer not the guys computer I am booting. It boots the guy off and it clears the list of users in the room ONLY on my computer.
Reply With Quote
  #15  
Old 03-01-2004, 02:17 PM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

did you put this:

Code:
Case "boot" sock.close AddText "System Message", "You have been booted!"

in the DataArrival Sub of the [u]Client Program[/vb] ?
Reply With Quote
  #16  
Old 03-01-2004, 02:28 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I messed around with it and I finally got it working right.

[vb]Private Sub cmdBoot_Click()
sock(List.ItemData(List.ListIndex).senddata "boot|boot"
DoEvents
sock(List.ItemData(List.ListIndex).Close
List.RemoveItem(List.ListIndex)
End Sub[vb]

The problem was where the sock lines are at, It kept showing up for being red...almost like a compile error. I had to move the () til it finally figured out what I wanted to say.

Now it actually boots whoever I want it to boot. When the user clicks Ok, they get an error. I'm going to try to fix that. But overall, everything works great. I greatly appreciate the help.

There is one other thing I would like to add to my Chat program. I would like to be able to ban IP Addresses. Is there a way that can be done?

Last edited by PlenoJure; 03-02-2004 at 02:05 PM. Reason: Added [vb] tags
Reply With Quote
  #17  
Old 03-01-2004, 03:10 PM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

yeah, after you accept the connection in the server app, you can check the ip address of the new connection against maybe a list of ip addresses or something..

if you are gonna have the banned ip's in a list, then you can change the sock_ConnectionRequest sub to this:

Code:
Private Sub sock_ConnectionRequest(Index As Integer, ByVal requestID As Long) Amount = Amount + 1 Load sock(Amount) sock(Amount).Accept requestID DoEvents dim i as integer for i = 0 to listBanned.ListCount - 1 if sock(Amount).RemoteHostIP = listBanned.List(i) Then sock(Amount).SendData "boot|Your IP is Banned" DoEvents sock(Amount).Close Amount = Amount - 1 Exit Sub End If next i End Sub



then, In the Client App, change the Case "boot" in the DataArrival sub to this:

Code:
Case "boot" sock.close AddText "System Message", msg(2)


then on the server, change the cmdBoot sub to this:

Code:
Private Sub cmdBoot_Click() sock(List.ItemData(List.ListIndex).senddata "boot|You Have Been Booted!" DoEvents sock(List.ItemData(List.ListIndex).Close List.RemoveItem(List.ListIndex) End Sub


i think that should work
Reply With Quote
  #18  
Old 03-01-2004, 04:09 PM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I entered the code and I went to test it. When the Client goes to connect to the server I get an error. I debugged the server and it highlighted this:

For i = 0 To listBanned.ListCount - 1

I dunno what to do.

How is the IP Ban going to work? By looking at the code, is it going to work just like the Boot method?
Reply With Quote
  #19  
Old 03-01-2004, 05:52 PM
Boss1315 Boss1315 is offline
Regular
 
Join Date: Dec 2003
Location: Pennsylvania
Posts: 69
Default

Quote:
Originally Posted by Timot
I entered the code and I went to test it. When the Client goes to connect to the server I get an error. I debugged the server and it highlighted this:

For i = 0 To listBanned.ListCount - 1

I dunno what to do.

How is the IP Ban going to work? By looking at the code, is it going to work just like the Boot method?




well, you have to add a list on the form called listBanned

then you can add ip addresses to it either by hardcoding them in or inputting them from a file..


yeah, it will work just like the boot method
Reply With Quote
  #20  
Old 03-02-2004, 07:02 AM
Timot Timot is offline
Centurion
 
Join Date: Feb 2004
Posts: 178
Default Re:

I made the banned list and I went to test it out. I went to boot myself and I got 2 errors.

Run-Time Error "9"
Subscript out of range

Run-Time Error "381"
Invaild property arry index
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web- Based Chat server (Geocities) psycofella Communications 1 08-23-2003 01:01 PM
chat server shawn Communications 3 06-19-2003 02:23 AM
simple client server chat prob chibishmoo Communications 3 06-17-2003 09:14 PM
Chat server Floppy Communications 8 05-29-2002 11:41 AM
Chat Program Server taj134 General 0 06-19-2001 08:31 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Chat Server Help!
Chat Server Help!
Chat Server Help! Chat Server Help!
Chat Server Help!
Chat Server Help!
Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help! Chat Server Help!
Chat Server Help!
Chat Server Help!
 
Chat Server Help!
Chat Server Help!
 
-->