Up:Tutorial?
[Tutorial is under construction]
Connect to SIGVerse controller via socket using Winsock (blocking mode) †
※ This section explains how to connect to SIGVerse controller (run on Linux) via socket from a client computer (Windows) using Winsock. The socket code is integrated to the controller, not the server.
※ The demo application in this tutorial is Receive images captured inside SIGVerse to local computer.
- Environment: C++.Net Windows Form Application program, Visual Studio 2008, Windows 7 (32bit).
- The script of this application is as follow:
- Build a form having 3 buttons (for the sake of clarity, but you can combine the functionality of these 3 buttons in a way you want):
- Connect: connect to controller
- Get Image: get image from controller to client computer
- Close: close a socket after receiving an image from controller
- When the button Connect is pushed:
- [Client] The sndmsg function is called to notify the controller that a client is about to connect.
- [Controller] After receiving the notification from client, the controller will call the accept function and then it wait for connection from client.
- [Client] Call the connect function to make a connection.
- When the button Get Image is pushed:
- [Client] Call the sndmsg to notify the controller to send image data.
- [Controller] After receiving the notification from client, the controller will open the image as a binary file, read this file and send to client as a block of 512 bytes (you can change this size).
- [Client] Receive blocks of data until no more data is received, and then save as a file.
- When the button Close is pushed:
- [Client] The sndmsg is called to notify the controller to close the socket.
- [Controller] After receiving the notification, the controller will close the socket.
※ Some problems:
- This tutorial used blocking mode socket. It means the controller will wait for a client connection and can not do anything during this period. I also show you a temporary solution but it's not so convenient. A better solution is using non-blocking mode, which will be presented in another tutorial [future work].
- This tutorial requires using Inamura Lab network or you have to use the port forwarding in order to use the sndmsg function. For more information about this function, please refer to this tutorial メッセージ送信ツールの作成?.
- The problem of this tutorial is by using socket, you have to close it after the first time you finish receiving data from controller, or else the next time you would get a mess. This is considered an open problem for readers to try.
Set up the environment †
Client side †
- Create a C++.Net Windows Form Application like this:
- Add a reference to the sigverse.dll. For more information, please refer to this tutorial メッセージ送信ツールの作成?.
Controller side †
- Basically, I reused this tutorial エージェント視点の画像取得? and modify the captureView.cpp. So you use that tutorial to build the environment at the controller side first. I will show you what to modify later.
- Add some more attribute to the RobotController class: