WP app using TCP socket client can not connect to socket server - windows-phone-7.1

I am testing a TCP socket client app communicate with Socket-Server in wiFi-environment.
1.) I am using VS2005 to create Console App for Socket-Server (Netframework v2.0)
1.1) : Launch the Console App in PC with an IPAddress : 192.168.1.100 and portNo 3456
Using Windows phone as Client to connect the Socket-server .
2.0 ) set Up wifi connection in the phone.
2.1) Start the App to connect the server in Wifi
the Client code to connect the server ( No compiled error )
//-- taking idea from :creating a TCP Socket client
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202858(v=vs.105).aspx
// create endpoint
var ipAddress = IPAddress.Parse(hostName);
var endpoint = new IPEndPoint(ipAddress, portNumber); // ( 192.168.1.100 , 3456)
// Create a stream-based, TCP socket using the InterNetwork Address Family.
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = endpoint;
...... to do task here
Result show : NotConnected or Connection Reset
a. can Socket work for windows phone in this manner ? Is there anything I miss out?
However, it work in WP emulator.
b. Any problem in communication between socket version in Netframework v4 for WP and socket ver 2.0 for WinForm or console App in VS25/ Netframework v3.5 in VS2008?
Appreciate your help.

Related

"No connection could be made because the target machine actively refused it" connecting to VerneMQ

I installed VerneMQ on an Azure Ubuntu 16.04 VM, and opened port 1883 inbound and outbound. VerneMQ is configured to listen on port 1883, has allow anonymous connections turned on, and vernemq has been started (vernemq start).
allow_anonymous = on
listener.tcp.default = 127.0.0.1:1883
I have created a C# console app on my Windows 10 PC to send messages to the MQTT broker on the VM. I am using NuGet package M2Mqtt version 4.3.0 and have opened 1883 both inbound and outbound in my Windows 10 firewall.
string broker = "<ip address>";
MqttClient client = new MqttClient(broker);
byte code = client.Connect(Guid.NewGuid().ToString());
I am getting connection refused error message when I try to connect.
uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException:
'Exception connecting to the broker'
uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException
HResult=0x80131500 Message=Exception connecting to the broker
Source=M2Mqtt.Net StackTrace: at
uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String
username, String password, Boolean willRetain, Byte willQosLevel,
Boolean willFlag, String willTopic, String willMessage, Boolean
cleanSession, UInt16 keepAlivePeriod) at
uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId) at
MQTTSendReceive.MQTT.SendMQTTMessage() in C:\Projects\19 10 12
MQTT\MQTTSendReceive\MQTTSendReceive\MQTT.cs:line 17 at
MQTTSendReceive.Program.Main(String[] args) in C:\Projects\19 10 12
MQTT\MQTTSendReceive\MQTTSendReceive\Program.cs:line 13
Inner Exception 1: SocketException: No connection could be made
because the target machine actively refused it :1883
I can't see where I am blocked.
You have told VerneMQ to listen on localhost (127.0.0.1) which means you will only be able to connect to it from the Ubuntu machine.
If you want to be able to access it from elsewhere you need to tell it to listen on all interfaces (0.0.0.0)
allow_anonymous = on
listener.tcp.default = 0.0.0.0:1883

Xamarin VS2015 ios app connect to web app api

I have a iOS app that I am building in Visual Studio 2015 with Xamarin. I also have a Web Application with an Api, no authorisation. But when I try to connect to the api I get an error saying "Connection Refused".
I call the api through the following code:
var client = new HttpClient();
var data = await client.GetAsync("http://localhost:7074/api/values/get");
Config your Web API with an IP Address, say local 192.168.x.x
And replace localhost by that IP
var data = await client.GetAsync("http://191.268.x.x:7074/api/values/get");
localhost will point to your iOS device/emulator, not the server. You need to specify the IP or FQDN in the url. Also be be sure the firewall is open and that IIS is setup to accept remote connections.
localhost is your iPhone / iPad or simulator (the device where you run your app). You have to change it to the IP/Domain of your server.
If the server is your dev machine, ensure, that your phone is connected to the same network (e.g. via WiFi), else you might have the same problem, because your dev machine might not be reachable.
You can find the IP of your dev machine by typing ipconfig | find "IPv4" into the console (on Windows).

Connecting to Java Server from iPhone Chat application using Socket

One of my iOS developer is trying to connect to my Chat Application server which is developed using Socket (Java).
When he tries to connect to Server using GCDAsyncSocket during debug I can see readStreamHeader() is executing which is throwing StreamCorruptedException.
Same thing is happening when I do telnet using cmd : telnet localhost 13000
I'm able to connect with my java created client application but not with iOS client. I believe socket in java and in iOS have different way of communication. Please HELP !

Connect ios devices to local server via wifi

I have a localhost server on my laptop. Can I connect ios device to this localhost server through wifi?
What settings I must set up on wifi connection?
By localhost server , i assume you are talking about a HTTP server .
If you know the port on which the server is listening to , note it down.
If you dont , generally web servers are attached to port 80.
If both laptop and ios device is connected to the same network.
Then first note down the IPAddress of you laptop.
In windows you can do so by typing : ipconfig in the command prompt
In Unix or Linux based systems : type ifconfig in the terminal.
Lets assume you found out that your ipaddress is 192.168.1.2
Note down this IP Address of your wifi adapter.
Now , just type in IPAddress:Port in the web browser of your ios device to access the server.
eg: Type in 192.168.1.2:80 on the url bar of ios device.

Connection refused on client and server, both are on MAC

I am using Mac book and having client and server running on same machine. Server opens socket whenever it has to send command to Client. Problem is Client opens socket at startup but whenever server opens on . Ip adress is different. I would like to know if i create tunnel between these 2 sockets. Right now, while in server i am getting "Connection refused" error.
Any help is appreciated.
Thanks
Just use 127.0.0.1 loopback address for testing your initial socket code. Server bind()s and listen()s on some known port, client connect()s to it. Once you figure out that setup you can move on to routing between real addresses.

Resources