0 0

TCPServer的send和write有什么区别?0

require "socket"  
 
server = TCPServer.new('127.0.0.1', 20000)  
print "Server started\n"
loop do  
  Thread.start(server.accept) do |s|  
#  puts s.to_hash
  print(s, " is accepted\n")  
  str="hello world"
      begin 
         puts "sending ... " +str
         s.send(str)
    #s.write(msg)
         sleep 2

      rescue Exception => e
		   print s
		  print(s, " is gone\n")  
		  s.close  
      end 
    end 
end  


如果是send 用任意客户端连接就会报错  远程主机强迫关闭了一个现有的连接
但是用write就可以,这两个方法有什么区别吗?
2012年11月15日 12:26

1个答案 按时间排序 按投票排序

0 0

send的参数是2个吧? 文档:  http://www.ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/BasicSocket.html

2012年11月16日 10:32

相关推荐

    nginx-tcp-server:基于Nginx的高性能TCP服务器

    nginx tcp server 基于nginx的高性能的TCP服务器模块。采用协程(makecontext)实现纯异步, 异步支持mysql,redis等常用的基于TCP的驱动。 本模块基于nginx的stream开发。只支持1.9.x以上的版本。 基于协程的异步实现...

    connx:一个简单的TCP ServerClient Go框架

    devfeel/connxA simple tcp server/client go framework.Feature:极其简单的使用代码经典Server/Client模式解决经典粘包问题Server支持主动关闭Client支持Send+Write\OnlySend模式提供默认的Message协议,自包含版本...

    基于TDI 的 TCP数据传输

    上位机包括tcp和tcp.cpp 1.1 对外函数说明 HANDLE TdiTcpOpen(); TdiTcpOpen用于打开设备,成功返回有效的句柄,失败返回INVALID_HANDLE_VALUE. BOOL TdiTcpClose(HANDLE hDevice); TdiTcpClose用于关闭设备,成功...

    .net 稳定 高效 易用 可同步 TCP 通信框架

    SocketListener.Server.RegeditSession += new Feng.Net.Tcp.SocketListener.RegeditSessionEventHandler(server_RegeditSession); RegeditSession 事件用于是否允许客户端连接此服务器。可以使用用户名,密码的...

    JAVA本地服务器-客户端逐字显示

    Please write an Server/Client application in which the Server can send a message” 厦门大学软件学院” to the Client by TCP protocol. The Client application should display the received message and ...

    基于naga开发的TCP客户端/服务器程序

    4、又例如,客户端,包括链接上,接收包,关闭链接后三个事件和write()方法: NIOService service2 = new NIOService(); NIOSocket socket = service2.openSocket(InetAddress.getLocalHost(), port); /...

    FTP服务器 C#

    string sendString = "220 FTP Server v1.0"; RepleyCommandToUser(user, sendString); while (true) { string receiveString = null; try { // 读取客户端发来的请求信息 receiveString = user....

    计算机网络第六版答案

    Hence, it becomes possible for the attacker to issue a command to all the nodes, that target a single node (for example, all nodes in the botnet might be commanded by the attacker to send a TCP SYN ...

    Nginx+Tomcat负载均衡

    命名如:(便于区别 我们只用两个来讲解 ,多个tomcat和两个原理是一样的) 1、server.xml配置 我们需要在一台机器上跑 2 个不同的 tomcat ,避免出现端口被占用的情况,为了规范统一,我们修改全部tomca端口。...

    一款比较好的网络性能测试工具

    -l, --len #[KM] length of buffer to read or write (default 8 KB) -m, --print_mss print TCP maximum segment size (MTU - TCP/IP header) -o, --output output the report or error message to this ...

    S7A驱动720版本

    - The string write from the OPC Server sometimes failed . This bug has been fixed - After driver uninstall, not all of the S7A-related registry entries were deleted. Now the registry will be ...

    delphi socket call php socket 例子

    delphi socket call php socket 例子,可根据需要扩展写成聊天室、网站助理类似淘宝助理,有订单提醒。 <?php //确保在连接客户端时不会超时 set_time_limit(0); $port = 10081 ; $ip = '192.168.1.102'; // ...

    iperf-3.9-win64.zip

    --logfile f send output to a log file --forceflush force flushing output at every interval --timestamps <format> emit a timestamp at the start of each output line (using optional format string as ...

    C#坦克大战网络版代码

    //// 跟java有区别 如果这句话放到while外面 就不能接受第二个坦克连入 IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0); while (true) { buf = uc.Receive(ref ipep); Console.WriteLine("a udp packet ...

    Ghost 8.3 系统备份软件

     使用Ghost进行系统备份,有整个硬盘(Disk)和分区硬盘(Partition)两种方式。在菜单中点击 Local(本地)项,在右面弹出的菜单中有3个子项,其中 Disk表示备份整个硬盘(即克隆)、Partition 表示备份硬盘的单个...

    Ghost 8.3 Enterprise

     使用Ghost进行系统备份,有整个硬盘(Disk)和分区硬盘(Partition)两种方式。在菜单中点击 Local(本地)项,在右面弹出的菜单中有3个子项,其中 Disk表示备份整个硬盘(即克隆)、Partition 表示备份硬盘的单个...

    Rust 的轻量级基于流的 WebSocket 实现。

    /// A WebSocket echo serverfnmain () {let server= TcpListener::bind ("127.0.0.1:9001" ).unwrap ();for streamin server.incoming () {spawn (move|| {letmut websocket=accept (stream.unwrap ()).unwrap ();...

    ICS delphixe10源码版

    send cash (Euro currency or US Dollars) in an envelop to my street address or buy a gift certificate at Amazon in the UK. I will then use it to buy books. Here is the direct URL at Amazon UK (nearest ...

    socket linux2

    perror("send to server failed:"); } // 向服务器传送消息 usleep(1000); memset(buf,0,100); memset(tm,0,50); getchar(); } } if(pid>0) //父进程用于接受消息并读取 { while(1) { read(sockfd...

    Qemu-1.0.1 for windows

    [,server][,nowait][,telnet][,mux=on|off] (tcp) -chardev socket,id=id,path=path[,server][,nowait][,telnet],[mux=on|off] (unix) -chardev udp,id=id[,host=host],port=port[,localaddr=localaddr] [,local...

Global site tag (gtag.js) - Google Analytics