# How to create a tpc serversocket in java?

**URL:** <https://discuss.akka.io/t/how-to-create-a-tpc-serversocket-in-java/10840>\
**Category:** Akka Libraries\
**Created:** [July 26, 2024, 6:43am UTC](https://discuss.akka.io/t/how-to-create-a-tpc-serversocket-in-java/10840 "2024-07-26T06:43:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnonymousUser](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@AnonymousUser](https://discuss.akka.io/u/AnonymousUser)\
**Post date:** [July 26, 2024, 6:43am UTC](https://discuss.akka.io/t/how-to-create-a-tpc-serversocket-in-java/10840/1 "2024-07-26T06:43:49Z")

</div>

How to create a tpc serversocket in java?

> This topic is based on a conversation between an anonymous user of Akka and our “Ask AI about Akka” bot in the documentation.

---

<div class="post-metadata">

**Author:** ![Ask-AI-Bot](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@Ask-AI-Bot](https://discuss.akka.io/u/Ask-AI-Bot)\
**Post date:** [July 26, 2024, 6:45am UTC](https://discuss.akka.io/t/how-to-create-a-tpc-serversocket-in-java/10840/2 "2024-07-26T06:45:44Z")

</div>

In Akka, you can create a TCP server socket using the Tcp manager. Here is an example of how to do it in both Scala and Java:  
Scala:

```auto
val binding: Future[ServerBinding] =
  Tcp(system).bind("127.0.0.1", 8888).to(Sink.ignore).run()

```

Java:

```auto
final ActorRef tcpManager = Tcp.get(getContext().getSystem()).manager();
tcpManager.tell(TcpMessage.bind(getSelf(), new InetSocketAddress("localhost", 0), 100), getSelf());

```

[Source](https://doc.akka.io/docs/akka/current/stream/stream-io.html)

In the Java example, the server is created in the `preStart()` method of an actor. The `TcpMessage.bind()` method is used to bind the server to a specific address and port. The `getSelf()` method returns a reference to the actor itself, which will handle incoming connections.

Please note that these examples are specific to Akka and may not apply to other contexts or frameworks.
