Link to home
Start Free TrialLog in
Avatar of --laser--
--laser--

asked on

Winsock multi user chat

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)
Avatar of abith
abith
Flag of India image

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
Avatar of InVisal
InVisal

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
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.
Avatar of --laser--

ASKER

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
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
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.
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...
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 :) .
"yes! that is just what i needed, thanks!!" :-)
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
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.
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.
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.
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
Could you post some of your code?  I'd be interested in having a look at it.
yup...maybe u can post u'r code here...so we can check n see clearly your structure.>:D
ok guys..i just bought a copy of visual studio.NET i think ill have a crack at it with .NET instead
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
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
the solution was not discovered for this question as i ended up giving up and doing it in a different language....
Avatar of DanRollins
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
Yeah, I think a PAQ and refund would do nicely.
thank you
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial