Results 1 to 22 of 22

Thread: i have Error when i make Send api function the my program donot recvie

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    i have Error when i make Send api function the my program donot recvie

    i have vb6 application client and server
    the server listen to port 2010
    and client connect to port 2010 and send string
    my server don't receive and i had close connection
    that code my server :

    Public Function winsockmain(ByVal hwnd As Long, ByVal uMsg As Long, _
    ByVal wparam As Long, ByVal lparam As Long) As Long
    winsockmain = CallWindowProc(lpwinsock, hwnd, uMsg, wparam, lparam)
    Dim lRetval As Long
    If uMsg = WM_SCOKET Then

    Dim ClientinternetAddress As sockaddr_in, AddressLen As Long

    Dim ReadBuffer(1 To 1024) As Byte

    Dim Data As String

    'On Error Resume Next

    Select Case lparam

    Case FD_ACCEPT
    LlistenClient = accept(wparam, ClientinternetAddress, ByVal AddressLen)

    WSAAsyncSelect LlistenClient, hwnd, WM_SCOKET, FD_READ Or FD_CLOSE

    frmServer.lblstatus.Caption = "Connected"
    If LlistenClient = SOCKET_ERRor Then

    frmServer.lblstatus.Caption = "Disconnected"

    End If

    Case FD_READ

    lRetval = recv(wparam, ReadBuffer(1), 1024, 0)
    Do
    If lRetval > 0 Then
    Data = Left(StrConv(ReadBuffer, vbUnicode), lRetval)

    If Left(Data, 5) = "Reply" Then
    Data = Right(Data, Len(Data) - 5)
    frmServer.txtchat.Text = frmServer.txtchat.Text & Data
    End If

    End If
    frmServer.lblstatus.Caption = "is " & Str(lRetval)

    If lRetval <> 1024 Or X = SOCKET_ERRor Then Exit Do
    Loop

    Case FD_CLOSE
    frmServer.lblstatus.Caption = "is " & Str(lRetval)
    'frmServer.lblstatus.Caption = "The Remote Machine Disconnected"
    End Select




    End If


    End Function

    and that code my client :

    Public Function SendData(ByVal s&, vMessage As Variant) As Long
    Dim TheMsg() As Byte, sTemp$
    TheMsg = ""
    Select Case VarType(vMessage)
    Case 8209 'byte array
    sTemp = vMessage
    TheMsg = sTemp
    Case 8 'string, if we recieve a string, its assumed we are linemode
    sTemp = StrConv(vMessage, vbFromUnicode)
    Case Else
    sTemp = CStr(vMessage)
    sTemp = StrConv(vMessage, vbFromUnicode)
    End Select
    TheMsg = sTemp
    If UBound(TheMsg) > -1 Then
    SendData = send(s, TheMsg(0), (UBound(TheMsg) - LBound(TheMsg) + 1), 0)
    End If
    End Function


    i work on windows 7
    Last edited by ssssm; Dec 18th, 2014 at 01:31 PM.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    The client is what is suppose to receive, the server sends the data however, the server will not send anything if there is not connection between the client and the server. There are several client/server examples in the VB6 and Earlier codebank to give you an idea.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    The client is what is suppose to receive, the server sends the data however
    That is not quite correct.

    Either the client or the server can send and receive once a connection is made. In fact normally one would expect to see data being sent from both sides back and forth.
    The lions share of that sending could be the server or the client depending on the app in question or the task at hand.

    For example if you are uploading data then the client does most of the sending, if you are downloading then the server does most of the sending but in either case both will do some sending and both will do some receiving.

  4. #4

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    i made aready connected to server :
    Private Sub cmdconnect_Click()
    Dim RemoteAddr As sockaddr_in
    LlistenSocket = socket(AF_INET, sock_stream, IPPRoto_tcp)
    If LlistenSocket = INVAlid_Socket Then
    frmclient.lblstatus.Caption = "unableto create socket "
    Else
    RemoteAddr.sin_family = AF_INET
    RemoteAddr.sin_port = htons(CLng("2010"))
    RemoteAddr.sin_addr = inet_addr("127.0.0.1")
    End If

    lRetval = connect(LlistenSocket, RemoteAddr, LenB(RemoteAddr))
    If lRetval = SOCKET_ERRor Then
    frmclient.lblstatus = "unable to connect to server"
    Else
    cmdconnect.Enabled = False
    cmdsend.Enabled = True
    cmddisconnect.Enabled = True
    WSAAsyncSelect LlistenSocket, Me.hwnd, ByVal WM_SCOKET, ByVal FD_CoNNECT Or FD_READ Or FD_CLOSE

    End If


    End Sub

    but had seem Error

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    That makes twice now that you have talked about getting an error but you still have not told us what the error was nor where it occurred.

  6. #6

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    i mean error when i send data connection have close and string data don't sent

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    So are you actually getting an error or are you just saying it is an error because you do not get the result you expect?
    If you are getting an error tell us what the actual error message is and what line it occurs on.

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    ssssm,

    Which line is giving you the error? What is the exact error you receive on the screen?


    Quote Originally Posted by DataMiser View Post
    That is not quite correct.
    Well, it would depend on whether of not the program is use multiple (array) of winsock controls or sockets.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    i am sorry maybe i mean problem i made if statement if connection have close say to me it close so when i made send data from client to server i had close connection and i had aredy made connected from cliect and i Succeed when i made connected but i cannot send any data




    Dim message As String
    Dim TheMsg() As Byte

    Dim sTemp$
    'If Len(txtsend.Text) = 0 Then Exit Sub
    message = "Reply" & txtsend.Text & vbCrLf
    'sTemp = StrConv(message, vbFromUnicode)
    'TheMsg = sTemp

    'lRetval = send(LlistenSocket, message, Len(message) + 1, 0)
    lRetval = SendData(LlistenSocket, message)

    here when i send the var lRetval return 0 and that not mean send any data


    and server is :
    lRetval = recv(wparam, ReadBuffer(1), 1024, 0)

    but not work too
    Last edited by ssssm; Dec 19th, 2014 at 08:39 PM.

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by ssssm View Post
    i am sorry maybe i mean problem i made if statement if connection have close say to me it close so when i made send data from client to server i had close connection and i had aredy made connected from cliect and i Succeed when i made connected but i cannot send any data
    Could you please upload the project to the thread so we can see for ourselves what the problem is?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by Nightwalker83 View Post
    Well, it would depend on whether of not the program is use multiple (array) of winsock controls or sockets.
    Why would you think that? Winsock can send and receive, both the client and the host can send and receive it doesn't matter if it is a single control or a control array. Multiple controls allow you to talk to more than one system at a time but have no bearing as far as restricting the sending to only one side or the other. One way communication is pretty much useless in most applications.

    One of my main products consists of a client/server system 1 server which is always listening on a given port. That server will open additional sockets as it accepts client requests, this way it can continue to listen on the main port and talk to one or many clients through the other sockets. The clients have only one socket and they send a lot of data and sometimes they also receive a lot of data.

    Anyway the point is that sending can occur from either end at any time once a connection is made. Which needs to happen first and how often depends on the software in question and what it needs to do.

  12. #12
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by DataMiser View Post
    Why would you think that?
    Last I heard the Winsock control could only either listen or send not both... correct me if I am wrong?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  13. #13

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by DataMiser View Post
    Why would you think that? Winsock can send and receive, both the client and the host can send and receive it doesn't matter if it is a single control or a control array. Multiple controls allow you to talk to more than one system at a time but have no bearing as far as restricting the sending to only one side or the other. One way communication is pretty much useless in most applications.

    One of my main products consists of a client/server system 1 server which is always listening on a given port. That server will open additional sockets as it accepts client requests, this way it can continue to listen on the main port and talk to one or many clients through the other sockets. The clients have only one socket and they send a lot of data and sometimes they also receive a lot of data.

    Anyway the point is that sending can occur from either end at any time once a connection is made. Which needs to happen first and how often depends on the software in question and what it needs to do.


    here is my project
    Attached Files Attached Files

  14. #14

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by Nightwalker83 View Post
    Last I heard the Winsock control could only either listen or send not both... correct me if I am wrong?
    i was do it(use reply with quote) but i was clear i words i am sorry

  15. #15
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    ssssm,

    You code appears to be methods such as

    Code:
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    
    End Sub
    which the Microsoft Winsock control has! Why don't you use the Winsock control?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by Nightwalker83 View Post
    Last I heard the Winsock control could only either listen or send not both... correct me if I am wrong?
    A winsock control can be set to listen in TCP mode in which case it will listen for a connection request. Once a request arrives then you either accept it or not. You can choose to stop listening and use the current control to handle the connection or you can pass the connection to another control.

    In either case you are not connected until the connection request has been accepted at which point you have a two way pipe for communications between the server and client either can send at any time and either will receive what ever has been sent from the other.

    Then there is UDP mode which requires no listener.

    In any case it is incorrect to think that a server can only send and a client can only receive and it is incorrect to think the opposite. Both sides can send and receive as much as needed.

  17. #17

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by Nightwalker83 View Post
    ssssm,

    You code appears to be methods such as

    Code:
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    
    End Sub
    which the Microsoft Winsock control has! Why don't you use the Winsock control?

    i use API function

  18. #18

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by DataMiser View Post
    A winsock control can be set to listen in TCP mode in which case it will listen for a connection request. Once a request arrives then you either accept it or not. You can choose to stop listening and use the current control to handle the connection or you can pass the connection to another control.

    In either case you are not connected until the connection request has been accepted at which point you have a two way pipe for communications between the server and client either can send at any time and either will receive what ever has been sent from the other.




    Then there is UDP mode which requires no listener.

    In any case it is incorrect to think that a server can only send and a client can only receive and it is incorrect to think the opposite. Both sides can send and receive as much as needed.


    i use API function and i use TCP

  19. #19
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: i have Error when i make Send api function the my program donot recvie

    I've never tried using API for this, it is quite simple using the Winsock control and I have not had any problems with it.

    I can't tell what your code is doing nor at what point it is failing. You should try setting some break points and stepping through the code at runtime in the IDE to see where it is running into issues or if the code is even being fired.

  20. #20
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by ssssm View Post
    i use API function
    I was asking why you don't use the control instead?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  21. #21

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by DataMiser View Post
    I've never tried using API for this, it is quite simple using the Winsock control and I have not had any problems with it.

    I can't tell what your code is doing nor at what point it is failing. You should try setting some break points and stepping through the code at runtime in the IDE to see where it is running into issues or if the code is even being fired.

    thank you and i am sorry for tired with me i will try with my project

  22. #22

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    47

    Re: i have Error when i make Send api function the my program donot recvie

    Quote Originally Posted by Nightwalker83 View Post
    I was asking why you don't use the control instead?



    thank you and i am sorry for tired with me i will try with my project

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