Solved

Winsock multi user chat

Posted on 2004-09-16
26
487 Views
Last Modified: 2013-11-13
hi everyone

i am trying to write a chat system for our networked pc's at home, it has to allow atleast 5 users to chat. what i need it for the user of one pc to be able to double click a name in a listbox and it will bring up a form that connects to the other user through a winsock connection. it needs to be able to work from any pc i.e. ANY user can chat to Any other user not just server/client. it would be great if it can handle more than 1 chat form at once also.

i just have absolutely no idea where and how to start...

all help will be greatly appreciated. thanks in advance

oh yeah also (this is optional) it would be really cool if the app can tell who is not available for chat and who is (for example who's pc is turned off and eho is on)
0
Comment
Question by:--laser--
  • 9
  • 6
  • 4
  • +4
26 Comments
 
LVL 5

Expert Comment

by:abith
ID: 12082952
hi laser

using one winsock you cannot connect to more than one port.  to use as a multichat you have to use the instance of the winsock. (i.e) you must have two winsock control for server and for client.

the server winsock index property must be set to 0 and it should be created in many instance.

for sample program you may get from

www.a1vbcode.com

regards
Abith
0
 
LVL 1

Expert Comment

by:InVisal
ID: 12084262
it hard to explain here so i give you a Link to source code

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=9166&lngWId=1
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=22418

if this not you want then goto this link

http://www.pscode.com/vb/scripts/BrowseCategoryOrSearchResults.asp?
chkCode3rdPartyReview=on &cmSearch=Search &optSort=CountDescending&blnResetAllVariables=TRUE  &chkCodeTypeZip=on&chkCodeTypeText=on&chkCodeTypeArticle=on &txtCriteria=winsock+multi+chat&chkCodeDifficulty=1%2C+2%2C+3%2C+4&lngWId=1

regards
InVisal
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12084466
Go to www.winsockvb.com for all your winsock needs.  There is really a lot of useful information there.

At this link is a tutorial for a person to person chat system, and I believe it even has a small example program:
http://www.winsockvb.com/article.php?article_id=15

This info at this link expands on what is learned in the first tutorial, giving you some information on dealing with multiple connections:
http://www.winsockvb.com/article.php?article_id=18

Most, if not all, of the code at the site is VB6 code, so I hope that is what you were looking for.  
Anyway, I hope the site helps you out; I know it's helped me out on numerous occasions.
0
 
LVL 4

Author Comment

by:--laser--
ID: 12094844
although these are great example chat programs, it is not quite what im looking for. what i need (if possible) is the program to listen for connections on 1 winsock and if i want to chat to someone else it connects to them using a seperate winsock (therefore requiring no server), the reason for this is i want to set up a network chat system at home and we dont have a permanently-on server, it is all just individual computers. for example if i have 3 networked computers and i want 2 of them to chat to each other without the 3rd one being on.

these comments and source code so far i greatly appreciate but maybe we need to take it 1 step further and take the server out of the loop
0
 
LVL 1

Expert Comment

by:craduza
ID: 12099611
hmm....quite a complex probs...but...why dont u design something that work like a server..means, whoever opening the chat will be a server...means, if there are 3 users that online, and opening the chat system, then there will  be 3 server. so each of them will ready for any conversation...if the user want to communicate with other user then the system will create a socket as client and using another user socket as server..:D isn't it easy?..:D
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12101944
Yeah, I would use a control array of Winsocks as described in the second link I gave you.  Have a Winsock listening on each client.  

When a connection request comes in, accept it on a newly created Winsock (as described in the link), and use that connection
to send messages back and forth.  That'll take care of the listening part, i.e. everybody will be ready to receive a chat request
and start chatting.

Now for initiating a chat request.  At the moment, I can't really remember if you can have some Winsocks in a Winsock control
array listening while you send with others.  I think you can, but it doesn't really matter.  Whenever you doubleclick on someone's
name in the listbox, create a new Winsock in the same control array you have for listening(or in a different control array).  Use
that Winsock to send a connection request to the other person, who, like you, will be able to receive it because he/she will always
have a Winsock listening.

I have no guarantee that the above idea will work, but it's all I could think of off the top of my head on this Monday morning.

Let me know if it does work, because now I am all curious.  And of course let us know if you need more help.
0
 
LVL 4

Author Comment

by:--laser--
ID: 12102216
that is EXACTLY what i am trying to do!! i havnt had much time to program lately because of family commitments but i will work on it ASAP and let you guys know. well well have to wait and see...
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12102270
Heh...

When you say, "that is EXACTLY what i am trying to do!!" do you mean, "Duh, you idiot, that's what I said in my first post!!" or
more like, "Yes! That is just what I needed, thanks!!"

In case you can't tell, I have a hard time judging tone of voice from text :) .
0
 
LVL 4

Author Comment

by:--laser--
ID: 12107719
"yes! that is just what i needed, thanks!!" :-)
0
 
LVL 5

Expert Comment

by:abith
ID: 12109166
hi laser

there is one more concept called port redirection.  Assume that client is connecting to the server in the port 100 then the server can redirect the port to some other number.

Or  the next idea is to keep one winsock for port allocation.

Regards
Abith .K
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12559978
I am fairly certain that the links I provided will provide laser with enough information to do what he needs to get done.  If you disagree, laser,
please let us know.  I hope you got everything worked out.
0
 
LVL 4

Author Comment

by:--laser--
ID: 12581286
actually i could never get the code to work properly...i agree winsockvb shows examples of p2p chat and multiple connections but i actually already knew how to do that. the problem i was having was that i cant get a single application to listen on one port and connect on the other because it says something about the address is already in use...also if one listens on a seperate port to the connecting one then it wont find a connection because it is 2 seperate ports.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:craduza
ID: 12632421
are u sure u're doing the right thing? bcoz, when it says address in use, it means that u have another program that use the same port and address as the server. so make sure u test it using 2 computers. hopefully u have the design in your mind.
0
 
LVL 4

Author Comment

by:--laser--
ID: 12637007
yeh im sure that im doin it right...i no that when 2 are usin the same port that it will be "address in use" but i thin they will have to use the same port...also i am usin it on 2 seperate computers
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12638755
Could you post some of your code?  I'd be interested in having a look at it.
0
 
LVL 1

Expert Comment

by:craduza
ID: 12641027
yup...maybe u can post u'r code here...so we can check n see clearly your structure.>:D
0
 
LVL 4

Author Comment

by:--laser--
ID: 12650951
ok guys..i just bought a copy of visual studio.NET i think ill have a crack at it with .NET instead
0
 
LVL 1

Expert Comment

by:craduza
ID: 12651921
ya..hopefully...hmm..just give u'r comment or idea if u have solve it..or if u have any probs, just post it here.>:D
0
 
LVL 4

Author Comment

by:--laser--
ID: 12722756
ok it seems to work fine in .NET maybe ill post it on planet source code so everyone can see it. thanks for your help guys but i couldnt work it in vb6 so i gave up
0
 
LVL 4

Author Comment

by:--laser--
ID: 12861351
the solution was not discovered for this question as i ended up giving up and doing it in a different language....
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 12869733
I recommend PAQ and refund.  
Even if the Asker did not find a solution, there is a good collection of links here that could help a future PAQ searcher with the same question.
-- Dan
0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12869863
Yeah, I think a PAQ and refund would do nicely.
0
 
LVL 4

Author Comment

by:--laser--
ID: 12880497
thank you
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12891690
Closed, 300 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 49
wordappend challenge 8 85
How does CurrentUser work? 10 25
Re-position the objects 7 51
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now