Socket connection using public IP on iPhone

49 views Asked by At

I'm having a requirement to connect my iPhone device with a tool(developed using python) via socket connection. Both the devices will be connected to a same wifi, I need to open a socket as a server using my public IP (ex. 192.168.166.168), which I will pass to the tool, and it will try and connect using the same with same port. I cannot use any AWS or 3rd party server, it has to be using public IP. I've tried many demos but can't somehow create a socket server using public IP. Any suggestions would be a great help, as I am totally new to socket programming.

So far I've tried using Starscream library to initiate the socket using a server, which works, but I do not want that, as I want communication to happen between 2 devices on same wifi without any web server involved.

My code using StarScream :

var request = URLRequest(url: URL(string: "wss://socketsbay.com/wss/v2/\(deviceID)/demo/")!)
request.timeoutInterval = 100
socket = WebSocket(request: request)
socket.delegate = self
socket.connect()

Reference link to the lib : https://github.com/daltoniam/Starscream

0

There are 0 answers