News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Socket Connection Closed And Reopened

Started by AgentSmithers, June 16, 2009, 07:10:54 PM

Previous topic - Next topic

AgentSmithers

In General when a Socket is closed from the opposing side, what API calls do you have to make before you can use Connect again? as of right now I call Socket and Connect to make a whole new socket but I feel its not necessary. Does close need to be called even though the connection is not established anymore? what needs to be done mandatory?

Link to a quick easy way to output a integer to a string?

I added Masm32Rt.inc and its saying all my invokes are
"invalid symbol type in expression" I believe its ADDR Var, where Var is a DB array.

So I cant use Str$ Or Hex$ to output the information just to debug =(

Edit: Anyone know where the heck FD_SET and FD_ZERO is for Select on Winsock so I can Invoke?

Edit2:
lea esi, offset AuthString + 6

                            invoke GetStdHandle, -11

                            mov STDHandle, eax

                            invoke WSAStartup,0101h,ADDR wsaData            ;Start Winsock

                            mov ax,AF_INET                                  ;Move AF_INET const to ax
                            mov sin1.sin_family,ax                          ;Move ax to sin_family in sin1 structure
                            invoke  inet_addr,ADDR AddrToCon                ;Invoke inet_addr to get Ptr to Ipaddress
                            mov sin1.sin_addr, eax                          ;Move EAX to sin_addr in sin1 structure
                            invoke htons,80 ;HTTP port                      ;Create Host To Network Short (16Bits)
                            mov sin1.sin_port,ax                            ;Move The 16Bit ax to sin_port in sin1 Structure

                            invoke socket,PF_INET,SOCK_STREAM,0             ;Create A Socket
                            mov s1,eax                                      ;Move The Results from socket to s1 Variable

                            @@:

                            mov byte ptr [esi], "0"

                            MainLoop:

                            invoke FD_ZERO, addr writeset
                            invoke FD_SET, s1, addr writeset

                            invoke select, NULL, NULL, addr writeset, NULL, NULL

                            invoke FD_ISSET, s1, ADDR writeset

                            .IF  eax == FALSE
                                invoke connect,s1,ADDR sin1,SIZEOF sin1         ;Connect To a Address
                                .IF eax == SOCKET_ERROR   
                                    xor eax,eax
                                    invoke WriteConsoleA, STDHandle, ADDR ConnectER, LENGTHOF ConnectER, ecx, 0 ;Uses 2Byte Tchar's
                                    ;invoke WSAGetLastError
                                .ENDIF
                                invoke WriteConsoleA, STDHandle, ADDR SelectNotCon, LENGTHOF SelectNotCon, ecx, 0 ;Uses 2Byte Tchar's
                                invoke StdIn,ADDR buffer, LENGTHOF buffer
                                jmp MainLoop
                            .ENDIF


I just cant seem to get this right, Under the event the internet disconnected or anything / Disconnects the best way to reconnect.

Edit: Is their a easy way to messure Time between API calls to test speed of a Proc / Command, or messure Clock Cycles?