-
2 Attachment(s)
[VB6] - Multi-User Chat Example (Winsock)
I wrote this last night out of boredom and after reading a lot of posts about people wanting to make a basic multi-user chat room.
This is the most stripped-down code I could come up with that does things "correctly". For that reason, some of the code may seem more complex than it needs to be but I commented it pretty well.
I am going to write a tutorial to go along with it, as soon as I get free time. ;)
One common mistake a lot of client/server programs make is they don't program according to the TCP (streaming) protocol. Sometimes "packets" get split up, truncated, sent together, etc. and this data arrival event is coded to expect that and handle it smoothly.
I set it up so you can add in your own commands easily to the Data Arrival event.
If you have any questions/comments/suggestions, post them here. I kept out most features like private messages, file transfers, web cams, etc. to keep things simple and straightforward, but if someone wants something added in here let me know.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
did i make you want to start this?
BTW, thanks for helping me out :)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by MrMakealotofsmoke
did i make you want to start this?
Yes, actually, your thread (and a few others) is what inspired me to write this.
Quote:
Originally Posted by MrMakealotofsmoke
BTW, thanks for helping me out :)
You're welcome. :)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
This is a nice lil project.
Is there a way that the Server could remove a user from the server and prevent their return?
What are some safe (safe = not likely to be in use) ports that can be used other than your default "1234"?
Thanks for sharing this.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Service Port
HTTP 80
FTP 20,21
Gopher 70
SMTP 25
POP3 110
Telnet 23
Finger 79
Local loops/callbacks 0
Here are some publicly acceptable ports for the corresponding commuincation types.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Debug.Assert
This is a nice lil project.
Is there a way that the Server could remove a user from the server and prevent their return?
What are some safe (safe = not likely to be in use) ports that can be used other than your default "1234"?
Thanks for sharing this.
Along with Hell-Lord's post, here's another list:
http://www.governmentsecurity.org/ar...ommonPorts.php
To remove a user from the server, do you mean to ban them? By IP? If you like, I can add that in there real quick.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
how about allowing people to change the text colour? not how you have it now.
but if a user bolds there text, it will be bold on the other clients comps too. know what i'm saying? This is what I am having difficulty doing atm.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
I'll add in text font/color/b/i/u, and IP banning. And I guess private messages while I'm at it.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by DigiRev
To remove a user from the server, do you mean to ban them? By IP? If you like, I can add that in there real quick.
Yes, thats what I meant. To remove a person from the chat "room"
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Debug.Assert
Yes, thats what I meant. To remove a person from the chat "room"
Adding in both a kick and ban feature. :)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Heres some more things you can add. invite only chats (must be in the chat room and invite someone to enter), password chats,and set a user limit on chats.
Allready have password chats in my messenger. working on invite only chats now. kinda like mIRC channel modes.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Thanks psycho.
I've decided since I'm adding in these other things I might as well make it multi-room also like mIRC. So next update will have:
- Private messages
- Font, color, bold/italic/underline, etc.
- Multiple rooms
- Invites to rooms
- Private and passworded rooms
- Other things like hyperlinks
Thanks for all the ideas, if anyone has anymore let me know.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
if he don't updateit soon. i'll update his source =)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Sorry I've been busy with work and other projects but I've already almost finished the update (which is a pretty big update). It will be uploaded tomorrow.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Ever tried smileys?
The only way I got it to work once was with the copy-from-clipboard method to RTF-box.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by TheBigB
Ever tried smileys?
The only way I got it to work once was with the copy-from-clipboard method to RTF-box.
You can insert them directly into the .TextRTF property but I prefer the clipboard method because the other one can be buggy from my experience. I've got so many other projects going on right now I don't know if I will get the smilies put in.
If you want smilies, then apparently you can ask psycho to put them in since he is planning on updating this code anyway. ;)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Sorry for another post. I've decided to just start from scratch and keep this first one as a basic example. The one I'm working on now will have more features than what is listed, so I hope this will satisfy everyone. :D It will be up sometime tomorrow afternoon/evening.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Sorry it's taking so long. I've gotten a lot of requests from people to add in even more features. :sick:
So I'm working on file transfers, web cameras, whiteboard, and more. You can visit this program's new website:
http://www.dannydotguitar.com/VBChat/
The site is new but I will be updating it so check back.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
I cant download your chat app on your website.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
It's coming soon. I've been working on a website for someone and it's taking all my time, but it's paying good money.
So I haven't given up on it or anything.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
have you given up yet digirev? or you just been busy? haha, just want to see if this project is still active.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
I am having troubles, me and my friend are trying this, and it works when he hosts the server but when i host he cant connect, it tells him he timed out, I tried turning off my firewall and it still gives him the time our message, has this happened to anybody else?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
you probably connect to the net with a router.
am I correct?
You'd need to set up an UPnP configuration.
Dunno how to do that, but solves problems for p2p applications.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
ok ill look into it, I have never heard of that before
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Here is a problem i encountered.
On my computer i run the server appkication
2. on another computer i cannot connect to the ip. Why?
Do i have to use telnet or what?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
what does the ip look like?
is it in the ranges:
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
btw, NAT traversal is the part I meant in the UPnP technologies
-
Re: [VB6] - Multi-User Chat Example (Winsock)
192.168 range, class c i believe, and holy crap I am lost with all this upnp and NAT traversal crap, I cant find any download links or anything
-
Re: [VB6] - Multi-User Chat Example (Winsock)
an ip in the ranges I mentioned is a 'private' ip.
it's your computer's ip within a network.
your network connects to the internet through a router. (which in for example my case is the wireless router)
the router has the public ip; the ip that connects you to the world. connections go to the router, and the router determines the destination of the packets within that private network.
problem is; winsock doesn't know what computer it should target behind the public ip.
you probably have the router and you act as server within the private network.
your friend sends a packet to your router, but as there is no further destination info the router doesn't know what to do with the packet so it dumps it.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
My ip looks like 192.168.1.72. Is there still a way where this can work? I never worked with winstock.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
you would need to setup port forwarding on your router. Log into your router, i'm not going to go into details on this, you can do a google search for the model number of your router and should find some kind of documentation. you need to forward the port that you're trying to connect on (example: port 2000) to your computers local IP (in your case 192.168.1.72). This lets the router know that if a connection comes in on 2000 that it should relay the connection to your IP. Without the port forward the router would deny the request.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
http://portforward.com/english/route...outerindex.htm
of course an automatic alternative would be better for an application.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Woot i got it to work i had to alter the ports telling it which ones to use. I have a few question.
1. Is there a way to restreive the list of online users and put them in a listbox? This listbox differs from the one in the chat window.
2nd. Is there a way with this code where i can add a button and make a new chat window and be able to privite chat with a selected user?
Thx!
-
Re: [VB6] - Multi-User Chat Example (Winsock)
try changing the ip address to localhost. it will connect to yourself no matter what. i'm also about to release sim-chat as open source. link in sig =]
-
Re: [VB6] - Multi-User Chat Example (Winsock)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
I have a question i have this code and i and wondering if this can be inserted into the messenger above. There is a problem thought evertime it send the smile it will popup with your picture editor to show the picture. Can this be added to the code above to send smileys?
vb Code:
Private Sub Command1_Click()
'First, just add plain text:
rchText1.SelText = rchText1.SelText & "Guest: " & Text1 & vbCrLf
'Then change what needs to be changed to pictures:
RefreshPics
DoEvents
rchText1.SelStart = Len(rchText1.Text) 'Put the start at the end, thats where you want to add the next line
Text1 = ""
Call Text1.SetFocus
End Sub
Private Sub Form_Load()
rchText1.OLEObjects.Clear 'Clear the ole objects to prevent errors
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
DoEvents
rchText1.OLEObjects.Clear 'You must add this or the
'program will crash. This doesnt
'happen in Windows 2k
DoEvents
End Sub
Sub RefreshPics() 'This scans the text for :) and (l)'s to change
Dim lFoundPos As Long 'Position of first character
'of match
Dim lFindLength As Long 'Length of string to find
Dim MakeSure As Boolean 'I have this to do the procedure twice, just to "make sure"
GoTo Skip:
Start:
MakeSure = True
Skip:
lFoundPos = rchText1.Find(":)", 0, , rtfNoHighlight)
While lFoundPos > 0
rchText1.SelStart = lFoundPos
'The SelLength property is set to 0 as
'soon as you change SelStart
rchText1.SelLength = 2
rchText1.SelText = ""
rchText1.OLEObjects.Add , , App.Path & "\smile.bmp" 'Add the picture after it has deleted the string
DoEvents
'Attempt to find the next match
lFoundPos = rchText1.Find(sFindString, lFoundPos + 2, , rtfNoHighlight)
Wend
If MakeSure = False Then GoTo Start
' I guess by changing or adding a few lines, you
' can make it add more pictures with different strings.
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1_Click
End Sub
-
Re: [VB6] - Multi-User Chat Example (Winsock)
No help? The code above works but i need help inserting it into the project. Can someone alter this code where it can send images?
Thx
-
Re: [VB6] - Multi-User Chat Example (Winsock)
This is better than the chat i have in my program already, may I use this instead???
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Hey guys...
Wow, I haven't been in here in forever. :D I've been so busy trying to land a good job, build up a portfolio, do some freelance webdesigning for money, etc., that I haven't had much time at all to work on anything in VB. :(
Anyway, that time is coming to an end and I will be able to get back to work on VBChat, the open source VB instant messenger.
I'll let you know as it progresses.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
lol I have a certian IP adress, but while I can connect to the chat thing, no one else can??????????
the port thing is set to port 1234, should that be changed?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
You're probably behind a router, making it unable for outsiders to access your chat-server.
Try redirecting port 1234 to your local IP if that's the case.
You should then also make sure you have the public IP address and not the local one.
Reserved (Default) Local IP's:
Code:
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
You can get your public IP by going to whatismyip.com.
And as I mentioned before in this thread, a guide to port forwarding.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
You are right, I have a router, what is the local and public IP address and how can I find them out?
EDIT: Ok I got my public IP its different than my local one though.
And when I find them, when people want to connect to my chat server what would they type in on the client end?
EDIT2: When I try to connect using my public IP and port 1234 I get the error connectionj forcefully rejected.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Look at the port forwarding I mentioned.
NOTE: you should be running the server application.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Ok I picked my router on the site, but it asks to select the program you are forwarding ports for from the list below
What would I pick?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
The last line says:
If you do not see the program you are forwarding ports for, be sure to visit our Default Guide for this router.
Click that Default Guide.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Ok it asks me if I want to forward a single port, is this what I want? And if yes, I want to forward port 1234?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Ok, I did it, but when I try to connect I get a time out error on my client end?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Justin M
Ok, I did it, but when I try to connect I get a time out error on my client end?
As was said before, the port needs to be opened (1234 unless you change it). You shouldn't be getting any error which is why I think either the port was not opened correctly, or there is a firewall blocking access.
Here are some steps you (or anyone else experiencing this problem) should follow:
1. Disable the Windows XP Firewall (or other firewall if you have one) or allow BOTH the server and client to access the internet through your firewall.
2. Go to Start -> Run -> and type "cmd" and press enter. (You may need to enter "command" for other versions of Windows). This will open a command prompt.
3. Type "ipconfig" and press enter. It should show your LOCAL IP address if you are behind a router (ie: 192.168.1.101). This is the IP address you will use to setup your router.
4. Now, you need to get into your router settings. You can usually do this by opening a web browser (Internet Explorer/FireFox, etc) and typing in your router's IP address. This is usually 192.168.1.1 or something like that.
5. It will prompt you for a username and password. The defaults are usually something like "admin/admin", "admin/administrator", etc.
6. Once you are in your router settings, you need to find "Port Forwarding". There are several fields. For the application name, enter anything, like "VBChat" or whatever. Then enter the starting port, and ending port. For this program, by default, the port is 1234. So enter 1234 in both boxes.
7. Then there is a "Protocol" dropdown box. This program uses TCP, but to be on the safe side, just select the "Both" option.
8. Enter the last 3 digits of your LOCAL IP, that was found in step #3.
9. Then save the settings. Close all instances of VBChat that you might have open, and restart it. It should work.
The quickest way, is to find the "DMZ" option in your router settings and enable it for your IP address. However, I don't recommend doing this as it opens ALL ports on your router and leaves your computer wide open.
-
Updating
I downloaded the source code and am currently adding in some more features (multiple rooms, private messages, maybe emoticons, webcams, file transfers, whiteboard, and probably a few other things so stay tuned :p).
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Thanks for the help, but in step 8:Enter the last 3 digits of your LOCAL IP, that was found in step #3 , where do I enter that?
-
1 Attachment(s)
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Justin M
Thanks for the help, but in step 8:Enter the last 3 digits of your LOCAL IP, that was found in step #3 , where do I enter that?
It should be in the port forwarding settings. Here is a screenshot.
-
1 Attachment(s)
Re: [VB6] - Multi-User Chat Example (Winsock)
Ok So I attached an image of my router settings, I am wondering if I did it right.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
That looks right if you entered the correct IP address. Now you should run the server and have people connect to you.
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Ok Could you do me a favor and see if you can connect to IP 192.168.2.12 with port 1234?
No one is in my chat room :(
-
Re: [VB6] - Multi-User Chat Example (Winsock)
192.168.2.12 is your lan ip
www.whatismyip.com to get your external ip. If u have a dynamic ip it will change every 24 hours or so
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Its my computer IP, so my external IP would be my router which is 142.167.89.15
What would I have to change?
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Justin M
Its my computer IP, so my external IP would be my router which is 142.167.89.15
What would I have to change?
Your router settings look right. You use your local IP (192.x.x.x) for that, like you did.
Your external IP (142.167.89.15) is what you give to someone who wants to connect to your server.
Edit: I am connected to your server so it works. :)
-
Re: [VB6] - Multi-User Chat Example (Winsock)
OMG thank you so much, sorry if I don't reply to you in the chat room I have to go to school but thanks a million!!!!!
-
Re: [VB6] - Multi-User Chat Example (Winsock)
Quote:
Originally Posted by Justin M
OMG thank you so much, sorry if I don't reply to you in the chat room I have to go to school but thanks a million!!!!!
You're welcome.
Next (big) version will be out in the next day or two, features I am including are:
File transfers
Webcams
Custom rooms
Password-protected rooms
Whiteboard
Private messages
Kick/ban
Those are what I have planned for now, I might think of some other ones in the process.