vb express + winsock api problem

hello,
i try to use the winsock api in my program but when i call the
WSAStartup from ws2_32.dll
i get an Access Violation Error (could not read/write protected memory).

I want to replace the System.Net.Socket because it causes some problems with packet loss/fragmented packets.
(when the remote server sends many packets, the socket puts them in one big packet which my program gets at the end of the async receive. This way the big packet has to be defraged and sometimes it even has incomplete packets at the end).

can you please help me with that or propose an other solution


Answer this question

vb express + winsock api problem

  • Aryan_Patel_05

    Sorry if this is a bit off topic but i can seem to find where i can "add" a winstock control to my program. I can in VB6 fine but vb express 2005 is so much different.

    Thanks, Shifty

  • khan2025

     Shifty wrote:
    Sorry if this is a bit off topic but i can seem to find where i can "add" a winstock control to my program. I can in VB6 fine but vb express 2005 is so much different.

    Thanks, Shifty


    Download mswinsck.ocx from the internet if you dont have it already.
    After that, right click on the toolbox and select to add a new control(cant remember the exact option's name).
    Finally, you will need to select COM Objects and browse for your mswinsck.ocx.

    i hope i helped.

  • Jazz Soft

    hello and thanks for the reply.
    what my application does is proxy the traffic between a local client and a remote server, and in some cases modify/create this traffic.

    I have already coded a function that can locate each message in the big packet that is received from the stream.
    also my proxy can handle the fact that some packets may be fragmented (which causes the last message at the end of the big packet to be incomplete) and can hadle this case, provided that the message ending will be received in the next stream.

    The problem appears when the message ending never arrives with any following stream.
    This causes an error in the client/server communication protocol.

    My main thought is that the server sends his message completed, but when my proxy socket (System.Net.Socket) receives it, some bytes are lost because of some kind of buffering issue.

    I want to replace the System.Net.Socket in my proxy with the real winsock api (or other alternative solution) just to see if my assumption is correct and the problem can be fixed.
    Thanks.

  • Jack2005

    well i have the file mswinstock.ocx. Now where do i have to put it to come up in vb. i allrey put it in "C:/windows/system32" but its not comeing up in VB :(

    Thanks :)

    Shifty

  • AlexSok

    Also,
    i tried using the winsock control COM object (mswinsck.ocx)
    but i get the error:
    Creating an instance of the COM component with CLSID {248DD896-BB45-11CF-9ABC-0080C7E7B78D} from the IClassFactory failed with HRESULT: 0x80040112(Class is not licensed for use (Exception from HRESULT: 0x80040112)).

    every time i try to add the control on my form or try to manually create a new winsock object.

    any way to fix that

  • Uday

     Georgios Xanthopoulos wrote:
    thanks for the reply again,
    hmmm yes, the symptom is that i stop receiving more data from the stream.

    i only use one receive buffer(byte array), but at each result of async receive, that buffer is cleared (Array.Clear) and the new data are copied to another location.
    After that the next BeginReceive is called.


    Could it be that the receive delegate throws an exception, which in turn prevents the following BeginReceive to be called

    Something that used to prove very useful for my own networking applications was to include three different types of network tracing, that I could individually turn on for debugging issues just like this:

    1: The networking API calls that I make and their return codes.
    2: The raw data sent/received along with the size of the data.
    3: The decoded messages.

    Of course, by default, all of these switches are turned off...

    Best regards,
    Johan Stenberg

  • DiaryAgenda

    If you really want to use mswinsck.ocx, this may help you out:

    PRB: Errors when you use Visual Basic 6.0 controls in Visual Studio .NET
    http://support.microsoft.com/ scid=kb;EN-US;318597

    Best Regards,
    Johan Stenberg


  • T0M101

    From your description, it sounds like you are using some kind of application level protocol that consists of "packets" (or messages) sent over TCP, and that you expect each write to read exactly one message, and each read to read exactly one message. If so, this is not a valid assumption (as you just have found out).

    TCP is a stream based protocol. It has no knowledge about message boundaries. It only gives you the guarantee that data will be received in the same order that it is sent. It is the application's responsibility to make sure that it can decode the *stream* of data that it receives.

    This includes handling the case where you have received only a partial message. Assuming that you will only get one message/read and never get a partial message *will* bite you sooner or later. It may work in *most* cases on *some* networks for *some* message sizes...

    My advice is to implement the decoding of messages in a way that can handle partial messages as well as multiple messages being read in a single read operation.

    Best regards,
    Johan Stenberg

  • LittleNew

    thanks for the reply again,
    hmmm yes, the symptom is that i stop receiving more data from the stream.

    i only use one receive buffer(byte array), but at each result of async receive, that buffer is cleared (Array.Clear) and the new data are copied to another location.
    After that the next BeginReceive is called.

  • rdrast

    While it is possible that you have stumbled upon a bug in the framework's socket implementation, personally I would start to look at my own code if I experienced a problem like what you describe. It is very easy to take a wrong step somewhere along the way when playing with asynchronous socket programming (I know that *I* have done so a couple of times over the years :))

    A couple of things that I'd make sure of is that I didn't incorrectly reuse the same receive buffer, and also that the defragmentation of the message worked as expected...

    When you experience your problems, are the symptoms that you don't receive any more data, or that there is a chunk of data "missing" in the middle of the stream

    Best regards,
    Johan Stenberg



  • vb express + winsock api problem