|
Seems like I cann't create a socket either with bind or Create with a parameter other than NULL
when do I get WSAEADDRNOTAVAIL
If I create a socket with Either Bind or Create with a NULL parameter for Create or Bind
ANd then I use GetSockame I get NULL for the IP address
IS this a strange occurence
|
|
|
|
|
ForNow wrote: IS this a strange occurence It's impossible to tell with this little amount of information. Show your code and the values of your variables and people will try to help you.
Use the best guess
|
|
|
|
|
a little background first I am writting a front end to the Hercules MainFrame Emulator this MFC C++ app
I also have a MVS started task communicating with this MFC C++ app when I first bought the Lap top
and moved in my code it worked the its a quad core lap top that I bought in August
Since then my machine has slowed and I am getting the timeouts
I Tried using Socket and Bind to Create the socket as opposed to just using the create
but in case it does take the IP address I use 192.168.1.4 which I think is the IP address of the laptop
I tried 192.168.1.111 as that is the ip address of my laptop 192.168.1.4 is routed to 192.168.1.111
I have a a loop in My CWinApp:: initinstance creating 4 socket threads
int i;
UINT start_port;
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
#ifdef _DEBUG
msOld.Checkpoint();
#endif
threadptr[i] = new SockCLeintThread(start_port);
#ifdef _DEBUG
msnew.Checkpoint();
if( diffMemState.Difference(msOld, msnew))
{
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
#endif
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";
threadptr[i]->flags.busy = 0;
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
WaitForSingleObject(*pevent,INFINITE);
}
in My CWinTread initinstance I try to create the socket
BOOL SockCLeintThread::InitInstance()
{
int error_code, threadpri;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
HANDLE mysocket;
int val = sizeof(int);
int *val_ptr = &val;
thisocket.Socket(SOCK_STREAM,FD_READ|FD_WRITE|FD_CONNECT,NULL,AF_INET);
if(thisocket.Bind(thisocket.port,NULL) == 0)
error_code = GetLastError();
int* len = new int;
thisocket.herccmd= new SOCKADDR;
if(thisocket.GetSockName(thisocket.herccmd,(int *)len) == 0)
error_code = GetLastError();
if(thisocket.GetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val_ptr, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.SetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.AsyncSelectFD_READ|FD_WRITE|FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT) == 0)
error_code = GetLastError();
if( thisocket.Connect(ipaddr,thisocket.port) == 0)
{
error_code = GetLastError();
}
else
flags.is_connected = 1;
return TRUE; }
the CASyncSockt::OnConnect
void SockClient :: OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
CHERC_CMDApp* main_app;
main_app = (CHERC_CMDApp *) AfxGetApp();
main_app->pevent->SetEvent();
if (0 != nErrorCode)
{
switch( nErrorCode )
{
case WSAEADDRINUSE:
AfxMessageBox("The specified address is already in use.\n");
break;
case WSAEADDRNOTAVAIL:
AfxMessageBox("The specified address is not available from the local machine.\n");
break;
case WSAEAFNOSUPPORT:
AfxMessageBox("Addresses in the specified family cannot be used with this socket.\n");
break;
case WSAECONNREFUSED:
AfxMessageBox("The attempt to connect was forcefully rejected.\n");
break;
case WSAEDESTADDRREQ:
AfxMessageBox("A destination address is required.\n");
break;
case WSAEFAULT:
AfxMessageBox("The lpSockAddrLen argument is incorrect.\n");
break;
case WSAEINVAL:
AfxMessageBox("The socket is already bound to an address.\n");
break;
case WSAEISCONN:
AfxMessageBox("The socket is already connected.\n");
break;
case WSAEMFILE:
AfxMessageBox("No more file descriptors are available.\n");
break;
case WSAENETUNREACH:
AfxMessageBox("The network cannot be reached from this host at this time.\n");
break;
case WSAENOBUFS:
AfxMessageBox("No buffer space is available. The socket cannot be connected.\n");
break;
case WSAENOTCONN:
AfxMessageBox("The socket is not connected.\n");
break;
case WSAENOTSOCK:
AfxMessageBox("The descriptor is a file, not a socket.\n");
break;
case WSAETIMEDOUT:
AfxMessageBox("The attempt to connect timed out without establishing a connection. \n");
break;
default:
TCHAR szError[256];
wsprintf(szError, "OnConnect error: %d", nErrorCode);
AfxMessageBox(szError);
break;
}
AfxMessageBox("Please close the application");
}
SockCLeintThread* threadptr;
threadptr = (SockCLeintThread *) AfxGetThread();
threadptr->flags.is_connected = 1;
AsyncSelect(FD_WRITE);
}
The CwinThread Derived Class
class SockCLeintThread : public CWinThread {
public:
DECLARE_DYNCREATE(SockCLeintThread)
public:
SockCLeintThread();
SockCLeintThread(UINT myport);
~SockCLeintThread();
CWnd *sendwindow;
CWnd *call_wnd;
char *thread_id;
SockClient thisocket; <== void Sendit(WPARAM, LPARAM);
void Receiveit(WPARAM, LPARAM);
LPCTSTR ipaddr;
BOOL idle;
struct {
unsigned int is_connected : 1;
unsigned int busy : 1;
unsigned int not_connected : 1;
} flags;
protected:
virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
};
The CAsyncSocket Derived Class
class SockClient : public CAsyncSocket
{
DECLARE_SERIAL(SockClient)
public:
SockClient();
SockClient(UINT myport);
~SockClient();
char *sockbuffer; int num_buff;
int thread_no;
UINT port;
SOCKADDR* herccmd; SOCKADDR MVS; int option;
private:
int busy; protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
};
I know its not formatted that neatly but I am always fixing the code
Thanks
|
|
|
|
|
ForNow wrote: I know its not formatted that neatly Understatement of the year!
Use the best guess
|
|
|
|
|
|
OK, but please don't just dump a load of code like the above, and expect people to figure out what's happening. Add some proper detail about exactly where it is going wrong and what the values of the relevant variables are at the time of the error.
Use the best guess
|
|
|
|
|
HI
Hope this is better
As I said I bought my quad core laptop in August and my code was running faster
as of now my connections time out
One of my questions is how come when I do a GetSockName after a Successful Bind
code is in The Dervied CWinThread SockCleintThread::Initinstance
The ip address in he SOCKADDR structure is 0 ?
The underlying technology was written By David "FISH" Trout
http://www.softdevlabs.com/Hercules/ctci-w32-readme.html[^]
class SockClient : public CAsyncSocket
{
DECLARE_SERIAL(SockClient)
public:
SockClient();
SockClient(UINT myport);
~SockClient();
char *sockbuffer; int num_buff;
int thread_no;
UINT port;
SOCKADDR* herccmd; SOCKADDR* MVS; int option;
private:
int busy;
protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
class SockCLeintThread : public CWinThread {
public:
DECLARE_DYNCREATE(SockCLeintThread)
public:
SockCLeintThread();
SockCLeintThread(UINT myport);
~SockCLeintThread();
CWnd *sendwindow;
CWnd *call_wnd;
char *thread_id;
SockClient thisocket; void Sendit(WPARAM, LPARAM);
void Receiveit(WPARAM, LPARAM);
LPCTSTR ipaddr;
BOOL idle;
struct {
unsigned int is_connected : 1;
unsigned int busy : 1;
unsigned int not_connected : 1;
} flags;
protected:
virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()
};
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
#ifdef _DEBUG
msOld.Checkpoint();
#endif
threadptr[i] = new SockCLeintThread(start_port);
#ifdef _DEBUG
msnew.Checkpoint();
if( diffMemState.Difference(msOld, msnew))
{
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
#endif
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";
threadptr[i]->flags.busy = 0;
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
WaitForSingleObject(*pevent,INFINITE);
}
BOOL SockCLeintThread::InitInstance()
{
int error_code, threadpri;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
HANDLE mysocket;
int val = sizeof(int);
int *val_ptr = &val;
thisocket.Socket(SOCK_STREAM,FD_READ|FD_WRITE|FD_CONNECT,NULL,AF_INET);
if(thisocket.Bind(thisocket.port,NULL) == 0)
error_code = GetLastError();
int* len = new int;
thisocket.herccmd= new SOCKADDR;
if(thisocket.GetSockName(thisocket.herccmd,(int *)len) == 0)
error_code = GetLastError();
if(thisocket.GetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val_ptr, SOL_SOCKET) == 0)
error_code = GetLastError();
if(thisocket.SetSockOpt(SO_KEEPALIVE | SO_DEBUG, &thisocket.option,val, SOL_SOCKET) == 0)
error_code = GetLastError();
if( thisocket.Connect(ipaddr,thisocket.port) == 0)
{
error_code = GetLastError();
}
else
flags.is_connected = 1;
return TRUE;
}
void SockClient :: OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
CHERC_CMDApp* main_app;
main_app = (CHERC_CMDApp *) AfxGetApp();
main_app->pevent->SetEvent();
if (0 != nErrorCode)
{
switch( nErrorCode )
{
case WSAEADDRINUSE:
AfxMessageBox("The specified address is already in use.\n");
break;
case WSAEADDRNOTAVAIL:
AfxMessageBox("The specified address is not available from the local machine.\n");
break;
case WSAEAFNOSUPPORT:
AfxMessageBox("Addresses in the specified family cannot be used with this socket.\n");
break;
case WSAECONNREFUSED:
AfxMessageBox("The attempt to connect was forcefully rejected.\n");
break;
case WSAEDESTADDRREQ:
AfxMessageBox("A destination address is required.\n");
break;
case WSAEFAULT:
AfxMessageBox("The lpSockAddrLen argument is incorrect.\n");
break;
case WSAEINVAL:
AfxMessageBox("The socket is already bound to an address.\n");
break;
case WSAEISCONN:
AfxMessageBox("The socket is already connected.\n");
break;
case WSAEMFILE:
AfxMessageBox("No more file descriptors are available.\n");
break;
case WSAENETUNREACH:
AfxMessageBox("The network cannot be reached from this host at this time.\n");
break;
case WSAENOBUFS:
AfxMessageBox("No buffer space is available. The socket cannot be connected.\n");
break;
case WSAENOTCONN:
AfxMessageBox("The socket is not connected.\n");
break;
case WSAENOTSOCK:
AfxMessageBox("The descriptor is a file, not a socket.\n");
break;
case WSAETIMEDOUT:
AfxMessageBox("The attempt to connect timed out without establishing a connection. \n");
break;
default:
TCHAR szError[256];
wsprintf(szError, "OnConnect error: %d", nErrorCode);
AfxMessageBox(szError);
break;
}
AfxMessageBox("Please close the application");
}
***********************************************************************
* From MVS started Task
* A Select does all socket I/O including listens
* From MFC C++ herccmd
*
SELECT_IT DS 0H
EZASMI TYPE=SELECT, Issue Macro X
MAXSOC=MAXSOC1, SPECIFY MAXIMUM NUMBER OF SOCKETS X
TIMEOUT=TIMEVAL, X
RSNDMSK=RSNDMSK, READ MASK X
RRETMSK=RRETMSK, RETURN FROM READ X
WSNDMSK=WSNDMSK, WRITE MASK X
WRETMSK=WRETMSK, RETURN FROM WRITE X
ESNDMSK=ESNDMSK, X
ERETMSK=ERETMSK, X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
ECB=MY_ECB, MAIN TASK ECB X
ERROR=ERROR, Abend if Macro error X
TASK=MYTIE, X
MF=(E,MY_PARM)
|
|
|
|
|
ForNow wrote: The underlying technology was written By David "FISH" Trout Then I guess you know who to contact about this.
Use the best guess
|
|
|
|
|
Don't think it's strange that after I do a bind
Of a socket I cann't get its ip address
|
|
|
|
|
ForNow wrote: Don't think it's strange that after I do a bind Of a socket I cann't get its ip address Not if you read the documentation[^].
Use the best guess
|
|
|
|
|
Hi, I am working with network simulator - 3, where the programming language is C++, I have created two nodes and sending data from server to client, its showing number of packets sent, but its not receiving, showing 0! bytes in client side.
Please help me if any one knows NS-3.
Thanking you...
|
|
|
|
|
It would appear you have a firewall blocking it.
Find out which port(s) you need to allow through.
|
|
|
|
|
Hi, I have written the code for Elliptic curve cryptography, its working fine in compilers like MS visual C++, Codelite. But its not building and compiling in G++ (Ubuntu 12.04). What might be the problem.
If any any one have the C++ code for ECC, please share it to my mail manoj.7390@gmail.com
Thanking you...
|
|
|
|
|
Manoj7390 wrote: What might be the problem. It could be anything, but you need to provide some more useful details, such as compiler error messages etc.
Use the best guess
|
|
|
|
|
I am getting lots of errors like this..
main.cpp:(.text+0x1a6): undefined reference to `std::cout
main.cpp:(.text+0x1ab): undefined reference to `std::basic_ostream<char, std::char_traits<char>
>& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
main.cpp:(.text+0x1ba): undefined reference to `std::cout
main.cpp:(.text+0x1bf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
main.cpp:(.text+0x1e1): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
main.cpp:(.text+0x1fe): undefined reference to `std::cout
main.cpp:(.text+0x203): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
main.cpp:(.text+0x213): undefined reference to `std::cout
main.cpp:(.text+0x230): undefined reference to `std::cout
If it is not sufficient, i will send the whole code, i dont know how to attach the file here. Please give me your mail id, i will send you the code.
|
|
|
|
|
How do you invoke the C++ compiler (command line, please)?
You have to g++ (instead of gcc ), see, for instance here[^].
Veni, vidi, vici.
|
|
|
|
|
I am using CC - command for compiling, What is the command for g++
|
|
|
|
|
You are using the C compiler.
g++ is the command for invoking the C++ compiler, e.g.
g++ myapp.cpp -o myapp
If you are using a makefile, set CC=g++ .
Veni, vidi, vici.
|
|
|
|
|
Manoj7390 wrote: i will send you the code. No you won't. Just show us the first few lines of your source (where your #include statements are), and the lines that are producing the errors.
Use the best guess
|
|
|
|
|
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#include <math.h>
Plenty of errors are coming, i couldn't figure it out.
But my question is same program is running in other compilers but why it is not running in g++.
Might be there is a small bug.
|
|
|
|
|
Manoj7390 wrote: Plenty of errors are coming, i couldn't figure it out. Like I said, show us the line of code and the error message; the first two or three should be enough.
Manoj7390 wrote: Might be there is a small bug. Most unlikely, it is much more likely that the compiler cannot find one of the include files, or there is some other setting specific to g++ that you need to add. I do not have a Linux system so cannot test this.
Use the best guess
|
|
|
|
|
Thanks.. I have got the output.. I was using CC instead of g++.
It works with g++
Thank you...
|
|
|
|
|
Hi. I have written the program for turbo encoder, for every single bit, it gives three bits as output and I am storing it as a integer. Now the problem is how to concatenate these bits in the integer form.
for example...
int u = 1; int p = 0; int q = 1;
Answer = 101;
|
|
|
|
|
int Answer = (u << 2) | (p << 1) | q
Use the best guess
|
|
|
|
|
I cannot use shifting here, because i am considering bits in the integer form. if i shift, data will change know.
Suggest any other way to store bits in C/C++
|
|
|
|
|