Newsgroups: borland.public.cppbuilder.internet.socket
From: "Remy Lebeau \(TeamB\)" <no.s...@no.spam.com>
Date: Mon, 24 Apr 2006 11:08:43 -0700
Local: Mon, Apr 24 2006 2:08 pm
Subject: Re: TServerSocket SendText Exception
news:444cd08c$1@newsgroups.borland.com...
> Do you think that the Invalid Pointer Exception is coming from That is a possibility, if you are allowing messages to be processed while > the client not being present? you are still looping through the connections. When a client disconnects, the OnClientDisconnect event is triggered, and then the server posts a CM_DEFERFREE message back to itself. When that message is processed, the client socket is freed immediately. If you continue to access the socket after it has been freed, then your code has undefined behavior from that point on, and anything can happen. > The system I have setup should always have a client present; I You should not be relying on that behavior. You are not allowing your code > typically (and my test rig is setup this way) only have two client's > connected to the server application. They both get the same messages > no matter what and they should never leave (or disconnect from the > server). to handle unforseen issues, such as network/power outages, transmission errors, etc. > Also you stated earlier that I can't keep doing a sendtext until I get Please re-read what I said. What I actually said was that you have to call > a ClientWrite Event after a -1 was returned from a SendText. WSAGetLastError() in order to find out why SendText() is returning -1. The OnWrite event be triggered later on only when WSAGetLastError() returns WSAEWOULDBLOCK. Any other value is an actual socket error and the socket can no longer be used and must be reconnected. > Now you are saying I have to do a SendText (pump the message queue) Only for the specific code snippet that you showed, which would not work > so I know the state of the socket. given the way you showed it. You are now relying on a variable that cannot be set without the OnWrite event being triggered, and it cannot be triggered while you are still running a loop until the loop pumps the message queue fo r pending messages. I strongly suggest that you go to http://www.deja.com and search through the void __fastcall TServer::ServerSocketClientConnect(TObject* Sender, void __fastcall TServer::ServerSocketClientDisconnect(TObject* Sender, void __fastcall TServer::ServerSocketClientWrite(TObject* Sender, LPBYTE ptr = static_cast<LPBYTE>(MS->Memory); while( MS->Position < MS->Size ) if( MS->Position > 0 ) void __fastcall TServer::SendBufferToSocket(TCustomWinSocket *Socket, if( MS->Size == 0 ) while( BufSize > 0 ) if( (sent == 0) || (WSAGetLastError() != WSAEWOULDBLOCK) ) break; if( BufSize < 1 ) MS->Seek(0, soFromEnd); void __fastcall TServer::SendTextToSocket(TCustomWinSocket *Socket, void __fastcall TServer::SendMsg(const AnsiString &AMsg) void __fastcall TForm1::Button1Click(TObject *Sender) Gambit You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
