How to 'reset' or destroy socket before using it with SocketAccept
 
            41600: Socket errorDescriptionTask: NetworkingThe specified client socket is already in use. The client socket must not be created before calling SocketAccept.Program Ref. /Networking/createListeningSocket/SocketAccept/272
Any ideas how I can solve this?PROC createListeningSocket()server_ss:=SocketGetStatus(server_socket);IF server_ss<>SOCKET_CREATED THENSocketCreate server_socket;SocketBind server_socket,"127.0.0.1",1025;SocketListen server_socket;SocketAccept server_socket,client_socket \Time:=WAIT_MAX;TPWrite "Accepted a new connection";server_created:=TRUE;drawing_ready:=FALSE;state:="r";server_ok:=TRUE;TPWrite "SocketStatus: "+ValToStr(server_ss);ENDIFclient_ss:=SocketGetStatus(client_socket);IF client_ss=SOCKET_CREATED THENTPWrite "Client socket already created.";ELSEIF client_ss=SOCKET_CONNECTED THENTPWrite "Client socket connected";ELSETPWrite "Unhandled socket state: "+ValToStr(client_ss);ENDIF.....
Comments
- 
            The way to do it is to add ERROR handler to your procedure.Here is an example from the Rapid manual that will hopefully will give you some ideas.And there is a lot of predefined ERRNO in the system. There is also a couple of instructions that is commonly used in error handling likeRETRY: retries the instruction that made you end upp in the error handlerTRYNEXT: will take the program pointer to the instruction after the failing oneVAR socketdev server_socket; VAR socketdev client_socket; VAR string client_ip; PROC server_messaging() VAR string receive_string; ... ! Create, bind, listen and accept of sockets in error handlers SocketReceive client_socket \Str := receive_string; SocketSend client_socket \Str := "Hello client with ip‑address"+client_ip; ! Wait for acknowlegde from client ... SocketClose server_socket; SocketClose client_socket; ERROR IF ERRNO=ERR_SOCK_TIMEOUT THEN RETRY; ELSEIF ERRNO=SOCK_CLOSED THEN server_recover; RETRY; ELSE ! No error recovery handling ENDIF ENDPROC PROC server_recover() SocketClose server_socket; SocketClose client_socket; SocketCreate server_socket; SocketBind server_socket, "192.168.0.1", 1025; SocketListen server_socket; SocketAccept server_socket, client_socket\ClientAddress:=client_ip; ERROR IF ERRNO=ERR_SOCK_TIMEOUT THEN RETRY; ELSEIF ERRNO=ERR_SOCK_CLOSED THEN RETURN; ELSE ! No error recovery handling ENDIF ENDPROC Per Svensson
 Robotics and Vision Specialist
 Consat Engineering0
Categories
- All Categories
- 5.6K RobotStudio
- 401 UpFeed
- 21 Tutorials
- 15 RobotApps
- 306 PowerPacs
- 407 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.9K Robot Controller
- 363 IRC5
- 80 OmniCore
- 8 RCS (Realistic Controller Simulation)
- 853 RAPID Programming
- 31 AppStudio
- 4 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 110 Collaborative Robots
- 5 Job listings