• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala SocketChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.nio.channels.SocketChannel的典型用法代码示例。如果您正苦于以下问题:Scala SocketChannel类的具体用法?Scala SocketChannel怎么用?Scala SocketChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SocketChannel类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: TcpIncomingConnection

//设置package包名称以及导入依赖的类
package akka.io

import java.nio.channels.SocketChannel
import scala.collection.immutable
import akka.actor.ActorRef
import akka.io.Inet.SocketOption


private[io] class TcpIncomingConnection(_tcp: TcpExt,
                                        _channel: SocketChannel,
                                        registry: ChannelRegistry,
                                        bindHandler: ActorRef,
                                        options: immutable.Traversable[SocketOption],
                                        readThrottling: Boolean)
  extends TcpConnection(_tcp, _channel, readThrottling) {

  signDeathPact(bindHandler)

  registry.register(channel, initialOps = 0)

  def receive = {
    case registration: ChannelRegistration ? completeConnect(registration, bindHandler, options)
  }
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:25,代码来源:TcpIncomingConnection.scala


示例2: TcpWriteActor

//设置package包名称以及导入依赖的类
package spooky.io

import java.nio.channels.SocketChannel
import spooky.actor.Props
import spooky.actor.Actor
import java.nio.ByteBuffer
import spooky.actor.ActorRef
import spooky.io.TcpThread._
import java.util.concurrent.ConcurrentHashMap

object TcpWriteActor {
  def props(channel: SocketChannel, actors: ConcurrentHashMap[Tcp.Address, Tuple2[MessageActorRef, WriteActorRef]]): Props = Props(classOf[TcpWriteActor], channel, actors)
}
private[io] class TcpWriteActor(private val channel: SocketChannel, actors: ConcurrentHashMap[Tcp.Address, Tuple2[MessageActorRef, WriteActorRef]]) extends Actor {

  def receive: PartialFunction[Any, Unit] = {
    case Tcp.Register(messageActor, address, _, _) => {
      val previous = actors.put(address, (messageActor, self))
      assert(previous == null)
      context.become(traffic())
    }

  }
  private def traffic(): PartialFunction[Any, Unit] = {
//    case Tcp.Close => {
//      sender() ! Tcp.Closed
//    }
    case Tcp.Write(data, Tcp.NoAck) => {
      write(data.toByteBuffer)
    }
    case Tcp.Write(data, ack) => {
      if (write(data.toByteBuffer)) {
        sender ! ack
      }
    }
  }

  private def write(bb: ByteBuffer): Boolean = {
    if (!channel.isConnected) {
      Thread.currentThread.interrupt()
      false
    } else {
      while (bb.hasRemaining()) {
        channel.write(bb)
      }
      true
    }
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:50,代码来源:TcpWriteActor.scala


示例3: NioSocketChannel

//设置package包名称以及导入依赖的类
package knot.remote.channel

import java.net.SocketAddress
import java.nio.ByteBuffer
import java.nio.channels.SocketChannel

object NioSocketChannel {
  def apply(): NioSocketChannel = new NioSocketChannel(SocketChannel.open())
}

class NioSocketChannel(override val channel: SocketChannel) extends NioChannel(channel) {
  lazy val incomingBuffer: ByteBuffer = ByteBuffer.allocate(1)
  lazy val outgoingBuffer: ByteBuffer = ByteBuffer.allocate(1)

  def connect(socketAddress: SocketAddress): Boolean = channel.connect(socketAddress)

  def finishConnect: Boolean = channel.finishConnect()

  override def bind(address: SocketAddress): Unit = channel.bind(address)

  override def readInternal(): Int = {
    val r = channel.read(incomingBuffer)
    incomingBuffer.flip()
    r
  }

  override def writeInternal(bytes: Array[Byte]): Unit = {
    outgoingBuffer.put(bytes)
  }

  override def flushInternal(): Unit = {
    if (!isFlushPending) {
      setOpWrite()
      outgoingBuffer.flip()
      val r = channel.write(outgoingBuffer)
      log.debug(s"CLIENT: Write. $r")
      if (!outgoingBuffer.hasRemaining) {
        outgoingBuffer.clear()
        clearOpWrite()
      }
    }
  }
} 
开发者ID:defvar,项目名称:knot,代码行数:44,代码来源:NioSocketChannel.scala


示例4: TcpIncomingConnection

//设置package包名称以及导入依赖的类
package akka.io

import java.nio.channels.SocketChannel
import scala.collection.immutable
import akka.actor.ActorRef
import akka.io.Inet.SocketOption


private[io] class TcpIncomingConnection(
  _tcp: TcpExt,
  _channel: SocketChannel,
  registry: ChannelRegistry,
  bindHandler: ActorRef,
  options: immutable.Traversable[SocketOption],
  readThrottling: Boolean
)
    extends TcpConnection(_tcp, _channel, readThrottling) {

  signDeathPact(bindHandler)

  registry.register(channel, initialOps = 0)

  def receive = {
    case registration: ChannelRegistration ? completeConnect(registration, bindHandler, options)
  }
} 
开发者ID:rorygraves,项目名称:perf_tester,代码行数:27,代码来源:TcpIncomingConnection.scala


示例5: TcpIncomingConnection

//设置package包名称以及导入依赖的类
package akka.io

import java.nio.channels.SocketChannel
import scala.collection.immutable
import akka.actor.ActorRef
import akka.io.Inet.SocketOption


private[io] class TcpIncomingConnection(
  _tcp: TcpExt,
  _channel: SocketChannel,
  registry: ChannelRegistry,
  bindHandler: ActorRef,
  options: immutable.Traversable[SocketOption],
  readThrottling: Boolean
)
    extends TcpConnection(_tcp, _channel, readThrottling) {

  signDeathPact(bindHandler)

  registry.register(channel, initialOps = 0)

  def receive: PartialFunction[Any, Unit] = {
    case registration: ChannelRegistration ? completeConnect(registration, bindHandler, options)
  }
} 
开发者ID:rorygraves,项目名称:perf_tester,代码行数:27,代码来源:TcpIncomingConnection.scala



注:本文中的java.nio.channels.SocketChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala squaredDistance类代码示例发布时间:2022-05-23
下一篇:
Scala RuleTransformer类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap