Results 1 to 6 of 6

Thread: How can I fix this error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321

    Angry

    This is really driving me crazy, ive spent about an hour trying 2 work out whats wrong!!! And its probablyreally simple.

    Basically heres the code;

    Winsock1.RemoteHost = 10.0.0.2
    Winsock1.RemotePort = 1985

    Winsock 1.Connect

    #Continued#

    Any way, When run, it returns this error:

    "Run Time Error 40020, Invalid Operation at current state"

    The line that causes the error is;
    "Winsock1.RemoteHost = 10.0.0.2"

    I cant figure out why its happening!!!!!

    If you can help, please reply, thanks

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Hi AliBail,


    It seems to me that you should use a string .

    Winsock1.RemoteHost = "10.0.0.2"


    What protocol are you using? TCP or UDP because there is a difference.



    cheers
    Ray
    Last edited by marex; Mar 3rd, 2001 at 01:44 PM.
    Ray

  3. #3
    Addicted Member
    Join Date
    Mar 2000
    Posts
    148
    i thing the Winsock1 is open close it first

    Winsock1.Close
    Thanks For All Your Help!
    If I helped you I give God the glory

    From CodeGreen

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321

    Unhappy Im using the TCP protocal

    Im using the TCP protocol.

    I'll try closing the Winsock Connection first as well, But I think its closed anyway.

  5. #5
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Hi AliBail,


    I checked the doc files and you must use a string format
    with the winsock.remotehost statement.


    Thereis also a statemnet to set the protocol, but I assume that you
    have it in the properties of winsock1.

    [Code]

    Winsock1.RemoteHost = "10.0.0.2"


    This must work.


    Sample of TCP Connection

    1. Create a Standard EXE project
    2. Change the name of the default form to frmServer
    3.Change the caption of the form to "TCP Server"
    4. Draw a winsock control on the form and change its name to tcpServer
    5. Add two TextBox controls to the form. Name the first txtSendData, and the second txtOutput
    6. Add the code below to the form

    [Code]

    Private Sub Form_Load()
    'Set the LocalPort property to an integer
    'Then invoke the Listen method

    tcpServer.LocalPort = 1001
    tcpServer.Listen
    frmClient.Show
    End Sub

    Private Sub tcpServer_ConnectionRequest(Byval requestIS As Long)
    'Check if the control state is closed. If not,
    'close the connection before accepting new cooection.
    If tcpServer.State <> sckClosed Then
    tcpServer.Close
    End If
    ' Accept the request with the requestID parameter
    tcpServer.Accept requestID
    End Sub

    Private Sub txtSendData_Change()
    'The txtBox control named txtSendData
    'contains the data to be sent. Whenever the user
    ' types into the textBox, the string is sent
    'using the SendData method.
    tcpServer.SendData txtSendData.text
    End Sub

    Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
    'Declare a varable for the incoming data.
    ' Invoke the GetData method and set the Text.
    'property of a textBox named txtOutput to the data.

    Dim strData As String
    tcpServer.GetData strData
    txtOutput.Text = strData
    End ub

    The procedures above create a simple server application. However, to
    complete the scenario, you must create a client application.

    TO CREATE A TCP CLIENT

    1 Add a new form to the project,and name it frmClient
    2. Change the caption of the form to TCP Client
    3. Add a Winsock control to the form and name it tcpClient
    4. Add tow TextBox controls to frmClient. Name the first txtSend, and the second txtOutput
    5. Draw a commandbutton control on the form and name it cmdConnect
    6. Change the caption of the CommandButton control to Connect
    7. Add the code below to the form

    [Code]

    Private Sub Form_Load()
    ' The name of the Winsock control is tcpClient
    ' Note: to specify a remote host, you can use
    ' either the IP address (ex: "121.111.1.1") or
    ' the computer's "friendly" name, as shown here.
    'must be string type.

    tcpClient.RemoteHost = "RemoteComputerName"
    tcpClient.RemotePort = 1001
    End Sub

    Private Sub cmdConnect_Click()
    'Invoke the Connect method to initiate a connection

    tcpClient.Connect
    End Sub

    Private Sub txtSendData.Change()
    tcpClient.SendData txtSend.Text
    End Sub

    Private Sub tcpClient_DataArrival(Byval bytesTotal As Long)
    Dim strData As String
    tcpClient.GetData strData
    txtOutput.Text = strData
    End Sub


    The code above creates a simple client-server application. To try the two together
    run the project, and click connect. Then type text into the txtSendData TextBox on either
    form, and the same text will appear in the txtOutput TextBox on the other form.

    This will set you on the way I hope.

    Cheers
    Ray





    cheers
    Ray
    Ray

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Scotland, UK
    Posts
    321

    Smile Thanks

    Thanks

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