Hi ,
How to create a simple chat program in Vb using winsock.
I am having a listener socket at the server so
i am able to send messages from the client to the server.
But i am not able to send any acknowledgement messsage from the server to the client.
Kindly help.
i am also currently working on a chat program called "DIGI Chat". I guess if you have a look at my source code u'll understand everything! However i need a week or so to get it finish since it's got many functions like file transfer and white board and much more!
if u can wait for a week or so just tell me ur email and i'll mail the code to you when i finish/! or i can post the code on PSC for other people to have a look!
Are you putting two Winsock controls on the same form in the server application? Why?
Can you explain how you have written the code?
.
I am not a complete idiot. Some parts are still missing. Check out the rtf-help tutorial General VB Faq Thread Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink! Get more power for your floppy disks. ; View honeybee's Elite Club: Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
And if that response was mine, please think about giving me a rep. I like to collect them!
Yes you are right honeybee...i have 2 winsock controls since i assumed that 1 control for listening and 1 control for sending message to the client...correct me if i am wrong....and the comment is wrong in this line
Winsock2.RemoteHost = "aaa.bbb...." 'SERVER IP ADDRESS
it should be...
Winsock2.RemoteHost = "aaa.bbb...." 'Requesting Client IP adress
Mainly, the thing to note is that you need to employ a number of winsock controls for such an exercise, either by way of a control array or by way of a collection of Winsock objects.
The first winsock control acts as a listener, which only does the job of listening to any requests coming through on a certain port. Once a request arrives, it then searches the rest of the collection or array to locate a winsock that's available for connection. If such a control is available, the request is passed on to it, and thereafter the listening winsock forgets about the request.
If there is no winsock available for communication, meaning all are already occupied, you can either create a new instance or load another control in the array and proceed or send back an error message to the client telling the connections are full.
.
I am not a complete idiot. Some parts are still missing. Check out the rtf-help tutorial General VB Faq Thread Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink! Get more power for your floppy disks. ; View honeybee's Elite Club: Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
And if that response was mine, please think about giving me a rep. I like to collect them!
Here is some code. It might not be finished, I left it before completing it in all respects. But that will give you a fair idea of the server side part.
.
I am not a complete idiot. Some parts are still missing. Check out the rtf-help tutorial General VB Faq Thread Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink! Get more power for your floppy disks. ; View honeybee's Elite Club: Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
And if that response was mine, please think about giving me a rep. I like to collect them!
First off, for testing purposes, I changed the RemoteIPs in both projects to 127.0.0.1 to work on the same computer.
You should move the Winsock2.RemoteIP and port setting statements to the Form_Load in the server part.
Then in the cmdSend_Click event, use a loop similar to the one used in the client:
Do while Winsock2.State <>sckConnected
Winsock2.Connect
If Winsock2.State = sckError Then
'Error Handler
End If
Loop
Winsock2.SendData "Received"
Also in the client form add another textbox and use it to display the Winsock2_DataArrival from the server.
Another piece of advice, whenever developing such programs, test them with simple text messages first, instead of going for the database stuff. There could be confusion while debugging any errors. First make the code perfect with text messages and then customize it to suit your specific needs.
In order for the client to connect to the server, it is necessary that the server has already put Winsock1 in Listen mode. Also in order for the server to communicate to the client through its Winsock2, it is necessary that the client's Winsock2 is already in the listen mode. So it's best to start the listener in the form_load, and connect code in the Command Click event.
.
I am not a complete idiot. Some parts are still missing. Check out the rtf-help tutorial General VB Faq Thread Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink! Get more power for your floppy disks. ; View honeybee's Elite Club: Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
And if that response was mine, please think about giving me a rep. I like to collect them!