Results 1 to 14 of 14

Thread: Problem Sending Information Through Sockets

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Question Problem Sending Information Through Sockets

    Hi everyone.
    After a mountain of trouble, I was able to use winSock control in order to connect to the Gmail smtp server in order to send an Email by VB6 program I've made (such a long sentence!); But there's ONE LAST problem:
    the socket doesn't send or get information!
    Here's the code:
    Code:
    If sock.State = sckClosed Then
        sock.Protocol = sckTCPProtocol
        sock.RemoteHost = "127.0.0.1"
        sock.RemotePort = "2301"
        sock.Connect
      Else
        sock.Close
      End If
      lblStatus.Caption = "Sending"
      sock.SendData "helo"
    And I receive the following error:
    Code:
    Run-time error '40006': wrong protocol or connection state for the requested transaction or request.
    If I check the Status of the sock control after the Connect method, it DOESN'T equal to sckConnected, which means that the socket doesn't connect! And that's why I receive the error! But I don't know why and I don't know how to solve this. Can somebody help me troubleshoot this??
    P.N: the address is localhost, yes, but it's tunneled to the Gmail smtp server so don't worry about that part since the problem is not from there.

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    I forgot to mention that when I telnet the same address and port through command prompt, it works perfectly fine and I can send the Email. It's through the program that it causes problem. I appreciate any help from you.

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Problem Sending Information Through Sockets

    You are assuming that the connection happens instantaneously, which it doesn't. You need to code the sock_Connect event (which is triggered once the other end has accepted the connection request) and put your senddata there

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    Thanks a thousand times!
    I was totally stuck with this problem!! Now it works! ;D

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    OK there's another little problem now.
    Here's the code:
    Code:
    Private Sub sock_Connect()
    If sock.State = sckConnected Then
      lblStatus.Caption = lblStatus.Caption & Chr(13) & "Sending..."
      sock.SendData "helo"
      lblStatus.Caption = lblStatus.Caption & Chr(13) & "Email Was Sent Successfully!"
      Else
      lblStatus.Caption = "Error Connecting to the server!"
      End If
    End Sub
    Code:
    Private Sub sock_DataArrival(ByVal bytesTotal As Long)
        sock.GetData strData
        lblStatus.Caption = lblStatus.Caption & Chr(13) & strData
    End Sub
    After running this, the text of lblStatus will have "Sending... Email Was Sent Successfully!" and nothing else, but in fact, the server is supposed to return some data, and I was expecting to see that too, which I didn't. Please let me know if I'm doing something wrong! Thanks a lot!

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Problem Sending Information Through Sockets

    I expect the Server is expecting something like a Carriage Return Line Feed (vbCrLf) at the end of whatever you send.
    Code:
    sock.SendData "helo" & vbCrLf

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    I still have difficulties understanding the received data.
    When I try telnet under command prompt, I see the response clearly, but when I try to display them in vb, it's like a hash code! like ???????@?@#?????
    I don't know why! And when I try to send the commands anyway, I receive a bunch of these weird responses and Email doesn't get sent.
    What should I do?? Should I decode this somehow??

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    I attached the program, although it doesn't work without another program called STunnel that tunnels a local port to Gmail smtp server. The code should help.
    Please help me solve this problem
    Attached Files Attached Files

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Problem Sending Information Through Sockets

    Can you post the code in a .zip please, I can't read rar files.

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    I attached the .Zip file.
    Attached Files Attached Files

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Problem Sending Information Through Sockets

    In the dataarrival event define strData As String

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Re: Problem Sending Information Through Sockets

    That's right I can see the responses now! But... I can only read them 2 times, and the second time it gives me 2 responses so a total of 3 responses and then I receive nothing... I wonder why...

  13. #13
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Problem Sending Information Through Sockets

    What responses are you getting ?

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    9

    Unhappy Re: Problem Sending Information Through Sockets

    First, it gives me the message that it gives you when you connect.
    Second, I receive two of the responses at one moment. first one is the response gmail gives you when you send "helo" it's something like "Google smtp at your service"
    and second one the response of Gmail to "Auth Login" which is a weird hash code.
    these responses are natural and are exactly what I should receive.
    But the problems is that I don't receive anymore! It doesn't matter if I change the command, like if I send "helo" 10 times, it still gives me 3 responses...
    for some reason the socket doesn't send all of the information (only sends 3 of them...)
    and after all, I don't receive the Email...
    Do you have any ideas?

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