首页 > comp > gb.net > socket 
 en fr de es it nl pl pt pt_BR mk sq ca hu cs tr ar fa id vi ko ja ru zh eo
前一个  下一个  编辑  重命名  撤销  搜索  管理  
文档  
警告! 该页面未翻译。  参见英文版 
Socket (gb.net)
This class implements a socket client to allow your programs to connect with socket servers. TCP and Local (Unix sockets) connections are implemented.

代号
该类继承于 Streamgb.
属性  方法 
ByteOrder  EndOfFile  EndOfLine  Handle  Id    Close   

该类是可创建

属性  方法  事件 
Host  LocalHost  LocalPort  Path  Port  RemoteHost  RemotePort  Status    Connect  Peek    Closed  Error  Found  Read  Ready   

This class performs its work asynchronously, so the program will not be stopped while connecting, sending or receiving data.

This class is a derived from the class Stream, so you can use standard Stream & Input/Output functions to send and receive data, and to close the socket.

Sockets can be used if the library "gb.net" is included in the project. To include this library use the menu [Project] [Properties] [Components] tick the component "gb.net".

Example

' Gambas class file

PUBLIC MySock AS Socket

PUBLIC SUB Button1_Click()

  DIM sBuf AS String

  MySock = NEW Socket
  MySock.Connect("localhost", 7000)

  DO WHILE (MySock.Status <> 7) AND (MySock.Status > 0)
    WAIT 0.1
  LOOP

  IF MySock.Status <> 7 THEN
    PRINT "Error"
    QUIT
  END IF

  sBuf = "Hello over there.\n"
  WRITE #MySock, sBuf, Len(sBuf)

  DO WHILE Lof(MySock) = 0
    WAIT 0.1
  LOOP
  READ #MySock, sBuf, Lof(MySock)
  PRINT sBuf

  CLOSE #MySock

END

Remarks to this Example