Socket.LocalPort
----------------

Queries local port number.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Socket](component_Socket.md) | [8.0](newinversion80.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Socket.LocalPort"; SocketID ) 

**MBS**( **"Socket.LocalPort";** /\* Queries local port number. \*/  
**$SocketID**) /\* The socket ID received by [Socket.Connect](SocketConnect.md) function.e.g. $sock \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SocketID | The socket ID received by [Socket.Connect](SocketConnect.md) function. | $sock |

### Result

Returns number or error.

### Description

Queries local port number.  
This is usually 0 for a brand new socket.  
Does not work on Windows 7 or older (requires Vista on Windows).  
### Examples

Get local port and IP:

 Set Variable \[ $sock ; Value: MBS ("[Socket.Connect](SocketConnect.md)"; "monkeybreadsoftware.com"; 80) \]   
Set Variable \[ $$LocalPort ; Value: MBS ( "Socket.LocalPort"; $sock ) \]   
Set Variable \[ $$LocalIP ; Value: MBS ( "[Socket.LocalIP](SocketLocalIP.md)"; $sock ) \]   
Set Variable \[ $r ; Value: MBS ("[Socket.Close](SocketClose.md)"; $sock ) \]  
### See also

- [Socket.Close](SocketClose.md)
- [Socket.Connect](SocketConnect.md)
- [Socket.Listen](SocketListen.md)
- [Socket.LocalIP](SocketLocalIP.md)

### Release notes

- **Version 8.0**
    - Added [Socket.LocalPort](http://www.mbsplugins.eu/SocketLocalPort.shtml) and [Socket.LocalIP](http://www.mbsplugins.eu/SocketLocalIP.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 8.0pr6](https://www.mbsplugins.de/archive/2018-01-01/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 28th December 2017 , last changed 4th March 2023

  
[Socket.LocalIP](SocketLocalIP.md) - [Socket.NewTCPSocket](SocketNewTCPSocket.md)

[HTML Version](SocketLocalPort.shtml)