> **Experimental**
>
> `@aws-cdk/aws-gamelift-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# Port

Interface for classes that provide the connection-specification parts of a security group rule.

Obtainable from: Port.allTcp, Port.allUdp, Port.tcp, Port.tcpRange, Port.udp, Port.udpRange
Used as argument in: [BuildFleet.addIngressRule](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-gamelift-alpha.BuildFleet.html#addingressrule)

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`lib/ingress-rule.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-gamelift-alpha/lib/ingress-rule.ts#L43)

## Example

TypeScript:

```ts
declare const build: gamelift.Build;

const fleet = new gamelift.BuildFleet(this, 'Game server fleet', {
  fleetName: 'test-fleet',
  content: build,
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE),
  runtimeConfiguration: {
    serverProcesses: [{
      launchPath: '/local/game/GameLiftExampleServer.x86_64',
    }]
  },
  ingressRules: [{
    source: gamelift.Peer.anyIpv4(),
    port: gamelift.Port.tcpRange(100, 200),
  }]
});
// Allowing a specific CIDR for port 1111 on UDP Protocol
fleet.addIngressRule(gamelift.Peer.ipv4('1.2.3.4/32'), gamelift.Port.udp(1111));
```

Python:

```python
# build: gamelift.Build

fleet = gamelift.BuildFleet(self, "Game server fleet",
    fleet_name="test-fleet",
    content=build,
    instance_type=ec2.InstanceType.of(ec2.InstanceClass.C4, ec2.InstanceSize.LARGE),
    runtime_configuration=gamelift.RuntimeConfiguration(
        server_processes=[gamelift.ServerProcess(
            launch_path="/local/game/GameLiftExampleServer.x86_64"
        )]
    ),
    ingress_rules=[gamelift.IngressRule(
        source=gamelift.Peer.any_ipv4(),
        port=gamelift.Port.tcp_range(100, 200)
    )]
)
# Allowing a specific CIDR for port 1111 on UDP Protocol
fleet.add_ingress_rule(gamelift.Peer.ipv4("1.2.3.4/32"), gamelift.Port.udp(1111))
```

Java:

```java
Build build;

BuildFleet fleet = BuildFleet.Builder.create(this, "Game server fleet")
        .fleetName("test-fleet")
        .content(build)
        .instanceType(InstanceType.of(InstanceClass.C4, InstanceSize.LARGE))
        .runtimeConfiguration(RuntimeConfiguration.builder()
                .serverProcesses(List.of(ServerProcess.builder()
                        .launchPath("/local/game/GameLiftExampleServer.x86_64")
                        .build()))
                .build())
        .ingressRules(List.of(IngressRule.builder()
                .source(Peer.anyIpv4())
                .port(Port.tcpRange(100, 200))
                .build()))
        .build();
// Allowing a specific CIDR for port 1111 on UDP Protocol
fleet.addIngressRule(Peer.ipv4("1.2.3.4/32"), Port.udp(1111));
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.AWS.GameLift.Alpha
Build build;

var fleet = new BuildFleet(this, "Game server fleet", new BuildFleetProps {
    FleetName = "test-fleet",
    Content = build,
    InstanceType = InstanceType.Of(InstanceClass.C4, InstanceSize.LARGE),
    RuntimeConfiguration = new RuntimeConfiguration {
        ServerProcesses = new [] { new ServerProcess {
            LaunchPath = "/local/game/GameLiftExampleServer.x86_64"
        } }
    },
    IngressRules = new [] { new IngressRule {
        Source = Peer.AnyIpv4(),
        Port = Port.TcpRange(100, 200)
    } }
});
// Allowing a specific CIDR for port 1111 on UDP Protocol
fleet.AddIngressRule(Peer.Ipv4("1.2.3.4/32"), Port.Udp(1111));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdkgameliftalpha/v2
var build Build

fleet := gamelift.NewBuildFleet(this, jsii.String("Game server fleet"), &BuildFleetProps{
	FleetName: jsii.String("test-fleet"),
	Content: build,
	InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_C4, ec2.InstanceSize_LARGE),
	RuntimeConfiguration: &RuntimeConfiguration{
		ServerProcesses: []ServerProcess{
			&ServerProcess{
				LaunchPath: jsii.String("/local/game/GameLiftExampleServer.x86_64"),
			},
		},
	},
	IngressRules: []IngressRule{
		&IngressRule{
			Source: gamelift.Peer_AnyIpv4(),
			Port: gamelift.Port_TcpRange(jsii.Number(100), jsii.Number(200)),
		},
	},
})
// Allowing a specific CIDR for port 1111 on UDP Protocol
fleet.AddIngressRule(gamelift.Peer_Ipv4(jsii.String("1.2.3.4/32")), gamelift.Port_Udp(jsii.Number(1111)))
```

## Initializer

TypeScript:

```ts
new Port(props: PortProps)
```

Python:

```python
Port(props: PortProps)
```

Java:

```java
new Port(PortProps props)
```

C# / .NET:

```csharp
new Port(PortProps props)
```

Golang:

```go
NewPort(Props PortProps)
```

## Methods

- `allTcp(): Port // chainable` (static) — Any TCP traffic.

- `allUdp(): Port // chainable` (static) — Any UDP traffic.

- `tcp(port: number): Port // chainable` (static) — A single TCP port.

- `tcpRange(startPort: number, endPort: number): Port // chainable` (static) — A TCP port range.

- `toJson(): any` — Produce the ingress rule JSON for the given connection.

- `udp(port: number): Port // chainable` (static) — A single UDP port.

- `udpRange(startPort: number, endPort: number): Port // chainable` (static) — A UDP port range.
