How can a server know which client is connecting it while the client is using getInputStream:outputStream:? - nsnetservice

I am using hotspot to communicate with iPhone, I publish netservice and connect each other. While every client can find many devices, when one of them connect my device by using getInputStream:outputStream:, how can I know which one is connecting me? PS:I have tried to resolve IP, but IP address can change any time.

Make your hotspot send some defined credentials (such as a host name) on the first attempt to connect. When accepting an input stream, check, if these data are provided and you're all set.

Related

changing IP address between vpn and original ip

i'm executing a python code that uses request module.
because i'm using VPN for some reason, when i make some api calls it automatically uses host's ip address of vpn to make api call. but for the tasks implemented in the script should use my original ip address. And i don't want to disconnect the currently connected vpn.
So my question is that is there any way to use my original ip when using python request module by not disconnecting vpn?
You can have multiple network interfaces on a machine. You could I guess send some requests over a specific NIC (physical or virtual).

Reprogramming Pet GPS tracker to send data to my own server

sorry if this is the wrong "stack". I could not find a better suited.
I bought a GPS tracker for my dog, which came with a subscription, a SIM card and a poorly developed app.
I have cancelled my subscription and want to use the device to send location info to my own server.
The device has a micro USB input and a SIM card slot. There is not much more I know, but if you have questions which may help find the answer, I can try to take it apart a little more.
So basically, is there some way I can reprogram this device to use my own SIM-card and app?
Plugging the device into my computer does nothing(as expected) however it does register in devmgmt.
Do not worry about the actual reprogramming, I can handle that myself.
Thanks in advance
Edit:
Thank you for feedback.
Image provided.
It does not, as I first thaught, register in the device manager.
I do have an IMEI number for it, but I cannot see a manufacturer anywhere on it. It might be on the underside, but the battery is glued on there.
Based on the Model Number LK120 After some Googling I found a documentation with the following SMS commands. Link to documentation LK209
Note send the commands without Square Brackets
// I guess you've already done 1 and 2.
1 - Set Admin Number - admin123456 [YOUR_PHONE_NUMBER]
2 - Set APN - apn123456 [APN_DETAILS]
//123456 seems to be the password - If the company you got the tracker from provided a different password - try that.
3 - SET the IP and Port Number - adminip123456 [IP_ADDRESS] [PORT_NUMBER]
As this Tracker is either TCP or UDP based - Can't really tell without the actual protocols and User Manual - you will have to setup a TCP and UDP Server and see which Protocol the Tracking Device connects via.
There are a few free software that can setup a TCP/UDP Server on your local machine for testing. [https://packetsender.com/]
Note that the IP address you set on the Tracker must be your Public IP Address, not Local LAN IP Address. You can get the Public IP from here - https://www.whatismyip.com/
Also you will need to open the port of your choosing on your Router and forward the Port to your PC make sure the port is not in use by another application e.g. 9999. This is possible for most Routers. You should be able to access your router admin panel using a browser, details should be on your router.
Also open the port on your PC firewall.
You can always check if it is possible to connect to your Server by going to CMD and running the following command (or use the Packet Sender software to test)
telnet [PUBLIC_IP_ADDRESS] [PORT]
If you can connect via the above command then the tracker should also be able connect.
Note Let us know if the SMS commands work, you should get a response if they work.

What connection settings needs to be used in order to connect chat client to server?

So I am playing around in Visual Basic and I'm making a chat client and server. I already did both and tested it on local machine and works. Server listens to connection and records all activities. This is reflected in chat client.
Here's the line of code that I use in order to connect to the "chat server" on same computer.
Dim clientSocket As New System.Net.Sockets.TcpClient()
clientSocket.Connect("127.0.0.1", 8888)
Anyone know what kind of settings I would need in order to connect remotely to another computer that has the chat server running?
The short answer is that you need to change the IP. But the real question is how do you get the IP?
Now if this is just for fun or something, you could just PING the computer if you know the name or walk over to that computer and run something like IPCONFIG on it.
But, in the real world, with a real chat, when a client launches, you would then grab the IP programmatically and post it along with some other info, like the User Name, to a database or web service (which you also created) so other clients would know it is online. You would also need to remove that record or update it with an offline flag or something as well as handle cases where the client looses network connectivity or ends unexpectedly. You can see where I am going with this...
The point is, this needs to be the IP of the client you want to talk to. 127.0.0.1 always refers to the local computer or device.

PeerConnection based on local IP's

What I want is, basically, to create a connection between two different computers on same local network. But i want to do this by computers' local IP's. (like 192.168.2.23 etc)
This must be a totally local connection. no TURN or STUN Servers. I am not sure if this is possible. Because there are not much documentation/example/information about WebRTC.
So, how can I create a connection from my computer to another one just passing its local IP as parameter?
Update: To be more clear; imagine there is an html page contains some code that activates my camera and audio services. and another -almost same- page is open in other computer. Waiting a connection request... And there is a textbox in my page to type an IP belongs to other computer on my local network. type 192.168.2.xx and bingo! i have connection between me and other computer.
I want this process as IP based, because there may be more than 2 devices on the network. And all of them are possible devices to create connection. So i need to reach them by their IP's.
Any example code or explanation would be great! even if it tells that this is not possible.
Thanks
Peer discovery is a vital part in any WebRTC application. It's an expensive term for saying: "Hi, I'm computer 4 and I want to talk to you!".
See it as calling a friend over the phone. You need to dial his number first.
This part is not defined in the WebRTC standards. You need to implement this logic in your application. Once you know who you want to call, you need a way of exchanging vital information. This is called signaling, like flo850 put in his answer.
Signaling is needed before any peer-to-peer connection can be set up.
To come up with an idea for your use case of 7 devices in a LAN.
If you have these devices connected to for example a WebSockets server and are in the same channel.
The WebSockets server can be written to route messages to specific receivers.
Devices connected to the channel often are identified with some kind of ID, imagine you use the device's IP.
When you want to talk to computer 4 with IP 192.168.0.4 you send the exchange messages (signaling) on the channel to the receiver with ID, the IP of the device you want to connect with.
How to send the signaling (offer, answer) is described here with example code.
Hope this helps
Users usually sit behind NATs; that's why ICE concept implemented in WebRTC.
If both users are sitting behind same NAT; you can skip ICE servers by passing "NULL" parameter value over "RTCPeerConnection" constructor:
var peer = new [webkit|moz]RTCPeerConnection ( null );
Now, browser will use "host" candidates, also known as "local" candidates.
you still need a signaling server. During the ICE candidate search, your clients will exchange their local ip through this signaling server

GameKit/Peer-to-peer over internet

For an iOS app I am developing, I want multiple phone to connect to each other and be able to voice chat between those devices.
I have it working when both devices are on the same network. This was quite simple and most of the stuff I want to do, is possible.
But now I am adding internet support, which is quite a hassle. I'll first try to explain how I want to match the devices, using a small webservice I set up.
Server
Start a new GameKit session, with session-mode GKSessionModePeer
Find the "Peer ID" of the server on the session I just created
Create a new CFSocketRef on an free port and keep it ready to accept connections
Send Peer ID and Port number to my webservice, running on an external server.
WebService
Webservice receives the information and stores it together with an ID and the IP address of the client in a database.
Send ID back to Server, which displays the ID
Client
When the user chooses to use the "Online" feature of GameKit to search for games, I ask the user for an ID (where the user should input the ID the server receives).
Client connects to the webservice supplying the ID. The webservice returns the information about the session (IP, PORT, Peer ID) of the server.
The user tries to connect to the IP address, with the port information and set up an input and output stream with the server.
This does not work ofcourse, because my network does not allow incoming connections and a random port (from an external network).
But now the question is, how do I solve this? I want to be able to set up a peer to peer connection between 2 devices, those devices could be on the same network, but also on separate networks.
Is there a framework, example or anything showing how to do this? I want to be able to send data from device to device, without sending it to a server first.
I'm not aware of any frameworks that do this. I do however have a lot of experience with p2p networking across multiple networks.
One important rule I learned: when communicating between networks, don't create a direct connection unless necessary. There are just too many factors that can (will?) cause issues, such as firewalls, NATs, etc.
Sure, you can let the connection try first. You can try to connect to the given IP addresses*, but in most cases it will fail. Even when using UPnP and NAT-PMP, you'll find that in a lot of cases (more than half?) you won't be able to accept incoming connections at all.
So make sure to have a backup plan. Make a network layer abstraction that doesn't only listen(), but also connects to a server. That way, when you can't connect to the IPs* of the client, you simply setup a connection via the server and the network abstraction takes care of it all.
Let me reiterate the above: don't rely on incoming connections only, always have a backup plan.
* I write IPs because clients can have multiple local/remote IPs. Always iterate over all these IPs when connecting. Example: my phone has 2 local IPv4 addresses (10.0.0.172 and 10.8.0.2), and an IPv6 address ([2001:x:x::6]). Of these three addresses, only the IPv6 address is publicly reachable, and the two IPv4 addresses are on different subnets so whether you can connect to them depends on the subnet that the other client is on. Always try to connect to both, and fall back to a server-proxied connection when it fails.
** I mentioned IPv6, yes. Let's not forget that IPv6 is not limited by NATs, unlike IPv4, and this means that you're far more likely to get a good connection via IPv6 than IPv4, if supported.