1. Berka Frenfert
  2. PowerBuilder
  3. Wednesday, 10 August 2022 06:22 AM UTC

This winsock code runs for 2 or 3 times and after that i keep getting same error line: MSG.text = "Error 10035: sock not ready or nothing was sent to server". Could not find exact reason, look like multiple request handling is the problem because this morning after booting up system it worked and 2 records were received from client side. Not sure what to do. I am using this script in pbm_custom02. Please take a look.

 

string 			ls_request
int				li_clientlen
String TheData

	// Accept client requests
	clientsock = u_test.uf_accept(sock, TheAddress)

	// Get the data sent by client
	TheData = String(u_test.uf_getrequestdata(clientsock)) /// -1 when null received
	IF Trim(String(RecentError)) = "10035"  THEN
		MSG.text = "Error 10035: sock not ready or nothing was sent to server"
		u_test.uf_closesocket(clientsock)
		Return
	END IF
	
	IF Trim(TheData) = "-1" THEN
		MSG.text = "Error -1: something went wrong with server"
		u_test.uf_closesocket(clientsock)
		Return
	END IF

	
	/// decrypt the data
	n_bcrypt Blender
	String EncType = "AES", MyPas  =  "MySecretKey", MyVect = "MyPublicCryptKey"
	
	PlainData  = Blender.of_decrypthex(EncType, TheData, MyPas, MyVect )
	IF IsNull(PlainData ) Then
		MSG.Text = "Blender Error: of_decrypt failed. "
		u_test.uf_closesocket(clientsock)
		Return 
	End If
	
	/// extract and add row
	Event _Extract(TheData)
	
	
	
	IF Trim(ErrorBuffer) <> ""  THEN
		MSG.Text = ErrorBuffer
	ELSE
		MSG.Text = "This is What I got: " + String(RecentError) + " DATA: " + String( TheData)	
	END IF
	
	
	
	//Send some data back
		u_test.uf_senddata(clientsock, Blob("<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY><H1>I hear ya</H1></BODY></HTML>"))
	
	//Close client socket
	u_test.uf_closesocket(clientsock)

 

 

Accepted Answer
Berka Frenfert Accepted Answer Pending Moderation
  1. Wednesday, 10 August 2022 11:20 AM UTC
  2. PowerBuilder
  3. # Permalink

a simple sleep() call was needed. When I checked same source in debugger there was no issue so figured it out this simple way that need to sleep a bit.

Comment
  1. Armeen Mazda @Appeon
  2. Wednesday, 10 August 2022 15:13 PM UTC
Thanks for sharing the solution!
  1. Helpful
  1. Berka Frenfert
  2. Tuesday, 16 August 2022 07:47 AM UTC
Sharing is caring. Love it.

most welcome.
  1. Helpful
  1. Berka Frenfert
  2. Tuesday, 16 August 2022 08:54 AM UTC
Ah, forgot to let you know where sleep(.5) was used.

Added the sleep(.5) just before the uf_accept() function.



Sleep(.5)

/// Accept client requests

clientsock = u_test.uf_accept(sock, TheAddress)



  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 10 August 2022 12:34 PM UTC
  2. PowerBuilder
  3. # 1

I ran into the same issue with one of my programs. I added a call to the Windows API function Sleep for 25 milliseconds. The PB Sleep function takes seconds for its argument.

The error message for 10035 is:

WSAEWOULDBLOCK
10035 (0x2733)
A non-blocking socket operation could not be completed immediately.

Does your Winsock object have a call to the Windows API function FormatMessage? It can be used to get the error text.

Comment
  1. Roland Smith
  2. Tuesday, 16 August 2022 16:52 PM UTC
Yield is a good idea to try. The built-in Sleep function takes a long so passing .5 isn't going to sleep for a half-second.

The Win API function Sleep takes milliseconds. You could define that and call it SleepMS.
  1. Helpful
  1. Berka Frenfert
  2. Wednesday, 17 August 2022 08:54 AM UTC
There is no loop in my code but I will check how use of yield() is better. I used yield() in many loops but not as alternate to sleep().

Yes, the SleepMS is best thing i want to add in this winsock code. Thanks a lot.
  1. Helpful
  1. Berka Frenfert
  2. Wednesday, 17 August 2022 08:58 AM UTC
ah, i guess call back function will need yield() but I have in mind to post another question for it later.
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 16 August 2022 12:22 PM UTC
  2. PowerBuilder
  3. # 2

Here is an example of using FormatMessage to return the error text for a system error number.

Function ulong FormatMessage( &
	ulong dwFlags, &
	longptr lpSource, &
	ulong dwMessageId, &
	ulong dwLanguageId, &
	Ref string lpBuffer, &
	ulong nSize, &
	longptr Arguments &
	) Library "kernel32.dll" Alias For "FormatMessageW"

public function string of_geterrortext (long al_errornum);
Constant ULong FORMAT_MESSAGE_FROM_SYSTEM = 4096
Constant ULong LANG_NEUTRAL = 0
String ls_errmsg

ls_errmsg = Space(256)
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, &
			al_errornum, LANG_NEUTRAL, ls_errmsg, Len(ls_errmsg), 0)

Return Trim(ls_errmsg)

end function
Comment
  1. Berka Frenfert
  2. Wednesday, 17 August 2022 08:23 AM UTC
Thanks a lot Roland. I added the new function on my code and will use it everywhere i need Win API call. I just changed longptr to ulong and it worked nicely. :)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.