views:

22

answers:

0

hi guys,

i want to make a client - server application in c# with asyncronus socket programming and i want to send a simple image file from client to another client connected to the server. I've a serialized class that contain the property as username ecc.. and a variable in byte that containt an array of byte of image. The problem is that when i send a small picture the other client receive the image but when try to send an image of 60kb the client the "BeginReceive" of client not fire. What's the problem? How can i do to send a class serialized with with array of byte of an image ?

this is the server example:

private void ReceiveCallback(IAsyncResult result)
{

    CmdSv connection = (CmdSv)result.AsyncState;

    int num_read = 0;
    if (result.IsCompleted)
        num_read = connection.Socket.EndReceive(result);
    if (  num_read>0)
    {
        for (int i = 0; i < num_read; i++)
        {
            connection.TransmissionBuffer.Add(connection.buffer[i]);
        }

        if ( num_read == connection.buffer.Length )
        {
            connection.Socket.BeginReceive(
                connection.buffer, 0, connection.buffer.Length,
                SocketFlags.None, new AsyncCallback(ReceiveCallback),
                connection);
        }
        else  
        {
            CmdSv s = connection.BinaryDeSerialize();
            ..

            SendServer snds = new SendServer();
            snds.txtSend = s.snd.txtSend;                    
            snds.value = s.snd.value; ---> if comment this or send from client small image works fine 

            CmdSv cm = new CmdSv();
            cm.UsernameDevice = s.UsernameDevice;                  
            cm.TypeRequest = "Message";                
            cm.UsernamePC = s.UsernamePC;
            cm.snd = snds;

            List<CmdSv> cusTemp = (from cs in connectedSockets
                                   where cs.UsernameDevice == s.UsernameDevice
                                   select cs).ToList();

            cusTemp[0].Socket.BeginSend(cm.Serialize(), 0,
                cm.Serialize().Length,SocketFlags.None, Send, cusTemp[0].Socket);

            "s.snd.value;" is the byte of array of image reived from client throw async socket

            ..
        }
        ..
    }

tnx so much alex