Socket.NewUDPSocket
-------------------

Creates a new UDP Socket.

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

MBS( "Socket.NewUDPSocket" ) ### Parameters

none

### Result

Returns a new socket ID or error message.

### Description

Creates a new UDP Socket.  
Socket reference numbers are starting at 29000 and counting up for each new socket.  
For use with broadcast, we create IPv4 here.  
### Examples

Create a new UDP Socket:

 Set Variable \[$$sock ; Value:MBS ("Socket.NewUDPSocket")\]  
Create a new UDP socket for broadcast and listen on a port:

 If \[not (GetAsNumber($$sock ) &gt; 0)\]  
 Set Variable \[$$sock ; Value:MBS ("Socket.NewUDPSocket")\]  
 If \[GetAsNumber($$sock ) = 0\]  
 Show Custom Dialog \["Failed to create Socket"; $$sock \]  
 Exit Script \[\]  
 End If  
End If  
Set Variable \[$r ; Value:MBS ("[Socket.Listen](SocketListen.md)"; $$sock ; UDP Broadcast::Port )\]  
Set Field \[UDP Broadcast::Send Result\]  
Set Variable \[$r ; Value:MBS ("[Socket.SetDataAvailableHandler](SocketSetDataAvailableHandler.md)"; $$sock ; Get(FileName); "ReadMessage")\]  
Set Variable \[$r ; Value:MBS ("[Socket.SetBroadcast](SocketSetBroadcast.md)"; $$sock ; 1)\]  
Set Variable \[$r ; Value:MBS ("[Socket.SetMulticastLoop](SocketSetMulticastLoop.md)"; $$sock ; 0)\]  
### See also

- [Socket.List](SocketList.md)
- [Socket.Listen](SocketListen.md)
- [Socket.NewTCPSocket](SocketNewTCPSocket.md)
- [Socket.SetBroadcast](SocketSetBroadcast.md)
- [Socket.SetDataAvailableHandler](SocketSetDataAvailableHandler.md)
- [Socket.SetMulticastLoop](SocketSetMulticastLoop.md)

### Example Databases

- [Network/UDP/UDP Broadcast](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Broadcast.shtml#2ScriptAnchor_)
- [Network/UDP/UDP Receiver](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Receiver.shtml#1ScriptAnchor_)
- [Network/UDP/UDP Sender](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Sender.shtml#1ScriptAnchor_)

### Blog Entries

- [UDP Broadcast for FileMaker](https://www.mbsplugins.de/archive/2015-08-26/UDP_Broadcast_for_FileMaker/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 21st June 2018

  
[Socket.NewTCPSocket](SocketNewTCPSocket.md) - [Socket.Peek](SocketPeek.md)

[HTML Version](SocketNewUDPSocket.shtml)