• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • Last Modified:

How avoid error "10038:Socket operation on non-socket" sending stream through network

there is a cource code of a function, that sends screenimage to another computer thourh network:

void TForm1::Sent()
{          
try{
   int a=Screen->Width;
   int b=Screen->Height;
   TMemoryStream *h = new TMemoryStream();
   TJPEGImage* jpg = new TJPEGImage;
   HDC DC = GetDC(0);
   Graphics::TBitmap *bmp = new Graphics::TBitmap;
   bmp->Height = b;
   bmp->Width = a;
   BitBlt(bmp->Canvas->Handle, 0, 0, a, b, DC, 0, 0, SRCCOPY);
   jpg->Assign(bmp);
   jpg->CompressionQuality=25;      
   jpg->SaveToStream(h);              
   h->Position=0;
   NMStrm1->Host = Edit2->Text;
   NMStrm1->PostIt(h);
   ReleaseDC(0, DC);
   h->Free();
   jpg->Free();
   bmp->FreeImage();
   }
catch(...) {}
}


when 2-5 images is sent, the program throws error "10038:Socket operation on non-socket", how can I avoid it?
0
Karalius
Asked:
Karalius
  • 3
  • 2
  • 2
1 Solution
 
SalteCommented:
The error indicates that you try to do a socket operation on a handle that isn't a socket.

The code you provide have no socket operations so I am very sure that the error is not caused by that function but by some other code which you haven't shown us.

The error can occur if you open any handle that isn't a socket and then try to do send(), recv(), bind() etc on that handle.

Examine your network code and try to see where those handles come from.

Alf
0
 
KaraliusAuthor Commented:
I just can't solve it, here is whole program, on C++ builder 4, can somebody look for it?

class TForm1 : public TForm
{
__published:     // IDE-managed Components
        TNMStrm *NMStrm1;
        TNMStrmServ *NMStrmServ1;
        TOpenPictureDialog *OpenPictureDialog1;
        TImage *Image1;
        TEdit *Edit2;
        TLabel *Label1;
        TButton *Button1;
        TLabel *Label3;
        TListBox *ListBox1;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall NMStrm1InvalidHost(bool &handled);
        void __fastcall NMStrmServ1MSG(TComponent *Sender,
        const AnsiString sFrom, TStream *strm);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private:     // User declarations
clock_t start, end;
int n;
int a,b;
void Sent();
public:          // User declarations
        __fastcall TForm1(TComponent* Owner);
};

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::Sent()
{            
try{
   int a=Screen->Width;
   int b=Screen->Height;
   TMemoryStream *h = new TMemoryStream();
   TJPEGImage* jpg = new TJPEGImage;
   HDC DC = GetDC(0);
   Graphics::TBitmap *bmp = new Graphics::TBitmap;
   bmp->Height = b;
   bmp->Width = a;
   BitBlt(bmp->Canvas->Handle, 0, 0, a, b, DC, 0, 0, SRCCOPY);
   if(bmp==NULL) Close();
   jpg->Assign(bmp);
   jpg->CompressionQuality=25;
   jpg->SaveToStream(h);              
   h->Position=0;
   NMStrm1->Host = Edit2->Text;
   NMStrm1->PostIt(h);
   ReleaseDC(0, DC);
   h->Free();
   jpg->Free();
   bmp->FreeImage();
   }
catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{                  
while(Mouse->CursorPos.x>2){
    Sent();
    Sleep(300);
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrm1InvalidHost(bool &handled)
{                      
AnsiString NewHost;
if (InputQuery("Invalid Host", "Please Choose another host", NewHost)){
   NMStrm1->Host = NewHost;
   handled = true;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrmServ1MSG(TComponent *Sender,const AnsiString sFrom, TStream *strm)
{                     //gavimas
try{
  if (FileExists("temp.jpg"))  DeleteFile("temp.jpg");
  TJPEGImage *jpg = new TJPEGImage();
  Image1->Width=Screen->Width;
  Image1->Height=Screen->Height;
  jpg->LoadFromStream(strm);
  jpg->SaveToFile("temp.jpg");
  Image1->Picture->Assign(jpg);
  jpg->Free();
  }
catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
NMStrm1->Disconnect();
}
//---------------------------------------------------------------------------

0
 
SalteCommented:
I don't think it is the whole program, there is a reference to a function "PostIt" which isn't shown.

What is NMStrm?

Perhaps you have forgot to initialize the TNMStrm class properly?

Alf
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
KaraliusAuthor Commented:
it is whole program... and refenrance PostIt is like Form1->Caption, I didn't wrote this function.

but it is interenting that the program runs correct for some time and later it frowd error(the function Send() runs abaut 3 times). if i change the program, that it the sending stream's size would be very small, the program runs correct for much longer time (for example the function Send() runs abaut 30 times) .
So I think that after n-KB is sent, it throws exception.
0
 
KaraliusAuthor Commented:
delete this quastion
0
 
moduloCommented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20609032.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
moduloCommented:
Saving this Q as a PAQ and refunding the 85 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now