Ok, this is a repost of a question I asked yesterday... so could someone please help me with it.Ok, I am working on a chat program (two way). Anyway, heres what I know and think...
1. I can send as many messages as I want to from the computer to first send. It sends the message and closes the winsock port and that for some reason it won't go back into its listening state even though I tell it specifically
If Winsock1.state <> sckClosed Then Winsock1.close
Winsock1.LocalPort = 1000
Winsock1.Listen
2. The recieving second end will recieve as many times as I send (with a little hesitation after the first message), But in between messages it will not close the port and also is still listening
Thank you for making it a bit clear.
Any idea why?
Here's what I think you should do:
If Winsock1.state <> sckClosed Then Winsock1.close
Doevents
Winsock1.LocalPort = 1000
Winsock1.Listen
Doevents
I had the same type of problem when i wanted to do something and it never did it.
I found out from a book that the the sytem get stuck or something and use the doevents command to awake it to its task.
Explain your problem more precisely if this doesn't work
ravcam, for chat program, I would said that it is more better if you applied 2 Winsock control in the Server or both server/client (If yothen to make bidirection connection request).
Whereby, 1 Winsock is juz listen a certain port. and the others is an array to establish the connection between the server and client.
Hence, when there is a disconnection from client, you still have a winsock control that listen to the port without switching the mode.
Ok... those two segestions were great... they solved one of my problems, but it still refuses to close the socket when I tell it...
To make sure it is not my stupidity I have enclosed the project itself so that you can see what I meen... and while you are peeking at my code... can you tell me why it sends so slow after the first message?
I plan on doing that but for right now I am just playing around with it to learn it... I want to simulate all the steps with one control for learning purposes, once that is done I will play around with multiple controls.
Right now I am just aiming for two way between just two people.
ravcam, you code will not be able to run 2 instances at the same PC. 'coz you're set the Winsock to listen to a same port.
And you can do it as you code. you need to establish the connection and keep it. till the form is unloaded. So you can send any message anytime as long as the connection still on.
and the connection is only establish upon request by the user itself
Ok... send a few meesages to one computer with one end... then goto the other computer and try to send a message back... you will get an address in use error.
If you go to "netstat -a" in the command line before sending any messages back you will notice that the port is listening but it is also in "time_wait" with the end you were recieving from. It will only send back if only the "Listening" entry is present.
once connection is established(monitor this with winsock1.state), then just use send data, with no close. see how this goes, remember to take the listen code out of form_load, and have a listen button maybe??
what i mean is you may need to create a connect button. Upon the user click this button, the program should prompt for the remote PC IP and proceed to estalish the connection.
If the connection is up, then juz let it on till the form unloaded.