Results 1 to 16 of 16

Thread: Help... Please?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    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

    Output on recieving end from netstat:

    Proto Local Address Foreign Address State

    TCP #Local address# 0.0.0.0:1000 Listening
    TCP #Local address# 10.100.8.195:1000 Time_Wait

    Now for my question...

    1. Why won't it close when I tell it?

    2. How do I get it to do so?


    Thank you in ad vance for any help you can offer.

  2. #2
    Guest

    Thumbs up

    What you have said in the question is really uncear, next time make yourself more clear.

    Answer's to what i could make out.

    1) So, you close the socket from one end expect the other socket to close ad start listening again. Right?

    Ans)
    Type this:

    If Winsock1.state <> sckClosed Then Winsock1.close
    Winsock1.LocalPort = 1000
    Winsock1.Listen

    and also add this code

    Private Sub Winsock1_Close()
    winsock1.close
    end sub

    Your probelm should be solved

    2) I frankly could not understand what you mean. Reply to this query making yourself more clear

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    Basically it is not closing the socket when I tell it to, and it also refuses to go back into its listening state.

  4. #4
    Guest
    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

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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.

    Hope this tips help you

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    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?
    Attached Files Attached Files

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    Thanks Chris,

    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.

  8. #8
    I tested it and it does close???

  9. #9
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    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.

  11. #11
    you explanation shows that u have a connection, are u doing it on the same, or 2 different ones???

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    I know you can only run one instance on any computer...

    I have it running on two different computers.

    And as for the rest of what you said Chris...

    Can you please explain what this meens and the concepts behind it?

  13. #13
    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??

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    Am I understanding you right NeoBlade?

    Establish the connection and leave it open on both ends then send and recieve without closing until the program ends?

    I will try this tommorow, cause right now it is almost time to change classes.

  15. #15
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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.

  16. #16
    yeah u got it, keep connection until someone presses close, or ends the app, have a cmdbutton that calls winsock1.close, that always helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width