⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node14.html

📁 robocup3d littlegreenbats_howtorobocop-0.1.tar.gz
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!--Converted with LaTeX2HTML 2002-2-1 (1.71)original version by:  Nikos Drakos, CBLU, University of Leeds* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from:  Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>SocketComm</TITLE><META NAME="description" CONTENT="SocketComm"><META NAME="keywords" CONTENT="howtorobocop"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="howtorobocop.css"><LINK REL="next" HREF="node15.html"><LINK REL="previous" HREF="node13.html"><LINK REL="up" HREF="node13.html"><LINK REL="next" HREF="node15.html"></HEAD><BODY ><DIV CLASS="navigation"><!--Navigation Panel--><A NAME="tex2html248"  HREF="node15.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html244"  HREF="node13.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html238"  HREF="node13.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html246"  HREF="node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="/usr/share/latex2html/icons/contents.png"></A>  <BR><B> Next:</B> <A NAME="tex2html249"  HREF="node15.html">WorldModel</A><B> Up:</B> <A NAME="tex2html245"  HREF="node13.html">Tutorial</A><B> Previous:</B> <A NAME="tex2html239"  HREF="node13.html">Tutorial</A> &nbsp; <B>  <A NAME="tex2html247"  HREF="node1.html">Contents</A></B> <BR><BR></DIV><!--End of Navigation Panel--><H1><A NAME="SECTION00610000000000000000"></A><A NAME="secSocketComm"></A><BR>SocketComm</H1><P>The lowest layer in our architecture manages the communication with the simulation server. This communication is done through TCP sockets and consists of S-expressions (predicates) that the agent and server send back and forth. The SocketComm handles the connection to the server and sending, receiving and parsing of the messages.<P>When creating a SocketComm you have to supply a hostname and a port number to connect to. When running the server on the same computer as your agent with default settings, these are 'localhost' and '3100'. After creating a SocketComm, the first thing to do is open an actual connection by calling connect:<P><BR><IMG WIDTH="567" HEIGHT="67" ALIGN="BOTTOM" BORDER="0" SRC="img1.png" ALT="\begin{program}\begin{verbatim}SocketComm comm(''localhost'', 3100);comm.connect();\end{verbatim}\end{program}"><BR><P>The SocketComm keeps two internal message queues, one for input and one for output. These queues are filled and emptied, respectively, when calling SocketComm's update method. This call blocks until new data is received from the server:<P><BR><IMG WIDTH="567" HEIGHT="50" ALIGN="BOTTOM" BORDER="0" SRC="img2.png" ALT="\begin{program}\begin{verbatim}comm.update();\end{verbatim}\end{program}"><BR><P>SocketComm supplies several methods to place messages that should be sent to the server into the output queue. First of all, you can build your own predicate using the Predicate and/or Parser classes <A NAME="tex2html1"  HREF="footnode.html#foot190"><SUP><SPAN CLASS="arabic">5</SPAN>.<SPAN CLASS="arabic">1</SPAN></SUP></A> and put it directly into the queue by calling the send method:<P><BR><IMG WIDTH="567" HEIGHT="69" ALIGN="BOTTOM" BORDER="0" SRC="img3.png" ALT="\begin{program}\begin{verbatim}rf&lt;Predicate&gt; myPredicate = makeMyPredicate();comm.send(myPredicate);\end{verbatim}\end{program}"><BR><P>However, you can also leave the trouble of building the predicates to SocketComm by using the make*Message methods. These methods are also used by the init, beam and move* methods, which also place the messages directly into the queue for you.<P>The input queue holds the messages received from the server. To check whether there is a new message you can call hasNextMessage, to extract the next message you can use nextMessage:<P><BR><IMG WIDTH="567" HEIGHT="69" ALIGN="BOTTOM" BORDER="0" SRC="img4.png" ALT="\begin{program}\begin{verbatim}while (comm.hasNextMessage())rf&lt;Predicate&gt; message = comm.nextMessage();\end{verbatim}\end{program}"><BR><P>To conclude this section we present a typical way to have successful communication with the server:<P><BR><IMG WIDTH="567" HEIGHT="353" ALIGN="BOTTOM" BORDER="0" SRC="img5.png" ALT="\begin{program}\begin{verbatim}// Create the SocketComm and connectSocketCom......NextMessage())handleMessage(comm.nextMessage());}\end{verbatim}\end{program}"><BR><P><DIV CLASS="navigation"><HR><!--Navigation Panel--><A NAME="tex2html248"  HREF="node15.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html244"  HREF="node13.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html238"  HREF="node13.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html246"  HREF="node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="/usr/share/latex2html/icons/contents.png"></A>  <BR><B> Next:</B> <A NAME="tex2html249"  HREF="node15.html">WorldModel</A><B> Up:</B> <A NAME="tex2html245"  HREF="node13.html">Tutorial</A><B> Previous:</B> <A NAME="tex2html239"  HREF="node13.html">Tutorial</A> &nbsp; <B>  <A NAME="tex2html247"  HREF="node1.html">Contents</A></B> </DIV><!--End of Navigation Panel--><ADDRESS>Bram2007-11-18</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -