?
Solved

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

Posted on 2003-03-31
7
Medium Priority
?
892 Views
Last Modified: 2007-12-19
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
Comment
Question by:Karalius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 8238502
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
 

Author Comment

by:Karalius
ID: 8245804
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
 
LVL 12

Expert Comment

by:Salte
ID: 8245964
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
Technology Partners: 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!

 

Author Comment

by:Karalius
ID: 8253996
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
 

Author Comment

by:Karalius
ID: 8482619
delete this quastion
0
 

Expert Comment

by:modulo
ID: 8483478
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8501249
Saving this Q as a PAQ and refunding the 85 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question