Results 1 to 23 of 23

Thread: AxWinSock connection error

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Exclamation AxWinSock connection error

    I make a AxWinSock project, and when I connect with a IP:Port, pop up this error:

    HRESULT: 0x800a9c46

    Help me please D:

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: AxWinSock connection error

    .NET provides a whole namespace for working with sockets, i.e. System.Net.Sockets. You really should be using that namespace to write network code in .NET. If you have issues with it then you'll get more descriptive exceptions.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I already know it, but i have seen people with it and have the same error.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    Help please D:

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    HRESULT 0x800a9c46 translates into this error message:
    "Wrong protocol or connection state for the requested transaction or request"

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    And how can i solve it? Thanks a lot

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    Quote Originally Posted by pguti19 View Post
    And how can i solve it? Thanks a lot
    Well, I guess you need to change the code on line 127 because that might be the cause of the error.

    You haven't posted any code so there is no way anyone can tell you how to solve it.

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    My code is very basic, i'm starting with WinSock:

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            AxWinsock1.RemoteHost = TextBox1.Text
            AxWinsock1.RemotePort = TextBox2.Text
            AxWinsock1.Connect()
        End Sub
    
        Private Sub AxWinsock1_ConnectEvent(sender As Object, e As System.EventArgs) Handles AxWinsock1.ConnectEvent
            Label1.Text = "CONNECTED"
            Label1.ForeColor = Color.Green
            AxWinsock1.SendData("Connected!")
            Label1.Location = New Point(195, 247)
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            AxWinsock1.SendData(TextBox3.Text)
        End Sub
    
        Private Sub AxWinsock1_ConnectionRequest(sender As Object, e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles AxWinsock1.ConnectionRequest
            AxWinsock1.Close()
            AxWinsock1.Accept(e.requestID)
        End Sub
    
        Private Sub AxWinsock1_DataArrival(sender As Object, e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
            Dim data As String = ""
            AxWinsock1.GetData(data)
    
            RichTextBox1.Text &= (data & vbNewLine)
        End Sub
    
        Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
            AxWinsock1.Listen()
        End Sub
    End Class

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    As jmcilhinney already suggested. Start by replacing the ActiveX component with the .Net classes.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I didn't find a nice tutorial of it, but I'll search better.

    With .Net classes I'll have the same error. I read, searching this error in google, somebody who have it but with .net classes :S.

    Thanks again.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    Quote Originally Posted by pguti19 View Post
    With .Net classes I'll have the same error.
    Post the code you're using where you get this error when using the System.Net.Sockets.

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I have the code, and now tell me that the host expressly reject the connection.

    And, in some IPs that connect, when I send something, tell me that the host force the end of connection.

    Code:
    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Imports System.Threading
    
    Public Class Form1
    
        Dim Client As New TcpClient
        Dim Stream As NetworkStream
    
        Dim SendData(1000) As Byte
        Dim ReceiveData(1000) As Byte
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Client.Connect(TextBox1.Text, TextBox2.Text)
            Stream = Client.GetStream
            Timer1.Start()
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            SendData = Encoding.ASCII.GetBytes(TextBox3.Text)
            Stream.Write(SendData, 0, SendData.Length)
        End Sub
    
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            If Client.GetStream.DataAvailable Then
                Stream.Read(ReceiveData, 0, 1000)
                RichTextBox1.Text = "Server: " & Encoding.ASCII.GetString(ReceiveData)
            End If
            If Client.Connected = True Then
                Label1.Text = "CONNECTED"
                Label1.ForeColor = Color.LimeGreen
                Label1.Location = New Point(195, 247)
            End If
        End Sub
    End Class
    Thanks a lot, again.

    PD: I already had Firewall and Antivirus turned off.
    Last edited by pguti19; May 20th, 2013 at 05:18 PM. Reason: PD

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    So the server is rejecting your connection. So you're either trying to connect to the wrong connection or there's something wrong on the server side. There is no way of telling since all we see is that you're trying to connect to TextBox1.Text and you're relying on an implicit conversion of TextBox2.Text to an integer.

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    You are telling that the IP or Port are wrong?

    And it?: "And, in some IPs that connect, when I send something, tell me that the host force the end of connection."

    Sorry, Ii'm noob in this field and I'm spanish. Thanks for your patience

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    No, what I'm telling you is that the exception you say that you get tells you that the server has rejected your connection. I don't know if the IP or Port are wrong since I have no idea what you have in your textboxes.

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    But ALL IP's that I test tell me it, except the IP's of game servers (Like minecraft, etc..) But when try send something tell me:

    "The host force the end of connection."

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    If you can't tell us what you're trying to do then it's rather difficult to tell you what you're doing wrong. All communication must follow a specific protocol and there is no way of knowing what kind of protocol you're trying to follow. You can't just open up a random port number and then send any kind of information to that port. For example if you try to send something on port 80 there must be a web server on the other end and that is adhering to the HTTP protocol after you've done the initial handshaking you must send text that is understood by that protocol.

  18. #18

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I'm trying to connect to a web (IP:Port). I use port 80 and don't tell me that the host expressly reject the connection.

    Then, when I connect, what have to send?

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    Well, it depends on what you want to get back. Here's a quick example that access www.microsoft.com:
    Code:
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim client As New TcpClient()
        client.Connect("www.microsoft.com", 80)
        Dim textToSend As String = "GET / HTTP/1.1" & vbCrLf & _
                                   "Host: microsoft.com" & vbCrLf & _
                                   vbCrLf
    
        Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(textToSend)
        Using stream As NetworkStream = client.GetStream()
          stream.Write(data, 0, data.Length)
          data = New Byte(1024) {}
    
          Dim bytes As Integer = 0
          Dim responseText As String = ""
          Do
            bytes = stream.Read(data, 0, data.Length)
            responseText &= System.Text.Encoding.ASCII.GetString(data, 0, bytes)
          Loop While stream.DataAvailable
    
          MessageBox.Show(responseText)
        End Using
        client.Close()
      End Sub
    However if you want to access web servers you should really look into the WebClient class instead of using TcpClient.

  20. #20

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I don't understand this: (don't know what is)

    Code:
    "GET / HTTP/1.1" & vbCrLf & _
    "Host: microsoft.com" & vbCrLf & _
    vbCrLf
    The fails is that I don't recive the server answers.

  21. #21
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    That is a barebone HTTP GET request. Basically that is what your web browser would send to the web server if you navigate to http://www.microsoft.com (in reality the web browser would send more information than the above, but this is the minimum you need to send). The web server will then reply by sending you the page you have requested.

    When you say that you don't receive the server answer I'll bet that you actually didn't try my example. Start a new project, put a button on the form and paste in my code and run it. You'll get a message box showing the answer from the server (if you're connected to the Internet at the time that is).

    You still haven't told us what you really want to do and what you've tried. Your explanation this far has been similar to this:

    I call someone on the phone.
    I then say a few random words in Swahili.
    They just hang up.
    Why do they do that?

    I encourage you to read up on the HTTP protocol, if that is indeed what you want to learn. Just Google it and you get a bunch of results.

  22. #22

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    50

    Re: AxWinSock connection error

    I test it, when MsgBox appear means that it has connected with web, yes?

    I want that connect with google.com, for example. How can I make?

  23. #23
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: AxWinSock connection error

    I don't know because you still haven't told us what you want to do. You can either use my example and read up a bit more yourself or explain what you want to do. We need to know what you want to send to the server and what kind of result you expect to get back. I can't read your mind. Tell us how your program is supposed to work.

    As I've already mentioned; if you want to communicate via HTTP then using the WebClient is a better choice than to use the TcpClient.

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