Results 1 to 9 of 9

Thread: Chat....

  1. #1

    Thread Starter
    Lively Member bhaskerg's Avatar
    Join Date
    Mar 2001
    Location
    india
    Posts
    68

    Chat....

    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.

    regards,
    -Bhasker G

  2. #2
    Hyperactive Member
    Join Date
    Aug 2001
    Posts
    484
    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!

    happy???

  3. #3

    Thread Starter
    Lively Member bhaskerg's Avatar
    Join Date
    Mar 2001
    Location
    india
    Posts
    68
    No...i cannot wait until a week...


    Here is my server side code....

    Option Explicit

    Private Sub Command1_Click()
    Winsock2.RemoteHost = "aaa.bbb...." 'SERVER IP ADDRESS
    Winsock2.RemotePort = 1111 'The Listening port at the server

    Winsock2.Connect
    Winsock2.SendData txtToClient 'PROBLEM HERE
    End Sub

    Private Sub Form_Load()

    Winsock1.LocalPort = 1001
    Winsock1.Listen

    End Sub

    Private Sub Winsock1_Close()
    Close #1
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Accept requestID
    End Sub


    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Dim strIncoming As String
    Winsock1.GetData strIncoming, vbString
    txtReceive = strIncoming

    End Sub

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I am slightly confused by the code.

    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!

  5. #5

    Thread Starter
    Lively Member bhaskerg's Avatar
    Join Date
    Mar 2001
    Location
    india
    Posts
    68
    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

  6. #6
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    If you go to my website http://anandk.freehosting.net/custom.html you will find a link to another thread on Winsock where this type of thing has been discussed.

    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!

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    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.

    .
    Attached Files Attached Files
    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!

  8. #8

    Thread Starter
    Lively Member bhaskerg's Avatar
    Join Date
    Mar 2001
    Location
    india
    Posts
    68
    Honeybee...can u see my code and tell where i am wrong?
    Attached Files Attached Files

  9. #9
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    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!

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