Developer exception starting a client-server model on Eiffel net - sockets

I'm trying to establish a connection using sockets between 2 PC's on the same LAN using the Eiffel Programming Language. I'm trying to run the examples that are by default on the installation directory of Eiffel Studio. However right now I'm trying to make it on the same machine by addressing to localhost (127.0.0.1).
It works perfectly on Linux (Ubuntu 15.10) but on windows 7 I'm getting an exception when I try to run the client program. The code of the exception is 24 Unable to establish connection. The server program runs just fine and I already got a connection between a client on linux and a server on windows. I didn't find a solution to this exception on the documentation nor on other sites. Here is a screencap:
Screencap of the debugger
Here is a link to the doc:
https://www.eiffel.org/doc/solutions/Two%20Machines
Thank you in advance.

The issue might be caused by the fact that some ports are used and others are reserved by the system. In particular the port range 0-1023 is designated for use by common system and network services. Ports beyond this range can also be registered (e.g., Service Name and Transport Protocol Port Number Registry or List of TCP and UDP port numbers). System security settings could also prevent applications from using specific port numbers.
The solution is to look for and to use port numbers that are available for user applications. Ports currently used on Windows can be found with netstat -an, what can be used is related to TCP/IP and firewall settings. The simplest approach is to try using some other port numbers, e.g. in the range 1024-49151.

Related

Delphi 11 TClientSocket can't connect to localhost, Windows socket error : 10049

So i did this tutorial exactly the same and im getting the Windows socket error: 10049. This is the tutiroal: https://docwiki.embarcadero.com/CodeExamples/Sydney/en/Chat_Room_Socket_(Delphi)
What is the problem here?
The problem you are facing here is that you are stil using port 0 (default values for both TClientSocket and TServerSocket components).
You should change the port number of both client and server component to be something else than 0. I recommend using ports greater than 1024 in order to avoid using reserved ports.
In fact you might want to consider checking IANA Service Name and Transport Protocol Port Number Registry to make sure the port you will be using isn't registered to another application or service.
PS: Embarcadero should have provided information about the need to change port number used in their example.

How to find the port number in ubuntu 12.04?

I need to write my first socket program involving TCP connections. In the program I have created there is a client and server, both of which are the machine I am coding on.However,it requires that I pass the port number as a command line argument. How do I accomplish this?
The answer is simple : Make sure your server and your client agree on the port to use. As long as the port is available and can be used, set up the connected so that the client and server use that same port.
Here's a link that explain the different ranges available for TCP and UDP ports.
As an exemple, the port 3074 is used by microsoft for its Xbox live service. Making an application using this port might interfere with the service.
The port used will be defined either in a configuration file or hard-coded in the source code of both the server and the client. You should easily be able to find it with a quick look at the code or the directory which contains the application.

Is writing DHCP client on Windows Phone 8 even possible?

Since I haven't installed windows 8 on PC yet, I'm not able to compile my program for phone and test whether or not will it works.
The question is: can I use DHCP ports (67 and 68), create there sockets and send/receive data in my app?
Reference of Socket API doesn't mention anything, however those ports can be locked by system DHCP client.
Since DHCP is a simple UDP protocoll it should be possible. You just need to check if it is possible on wp8 to open the ports in that low range. In linux that requires root permission, but luckily we use Windows.

Bluetooth: how to create a socket for connecting to a service with specific UUID with Bluez?

I am working with the BlueZ libraries for managing the bluetooth stack under linux. I am trying to open a socket that should connect with a specific service whose UUID is known. I have successfully tried to open sockets between a server and a client following the examples here:
http://people.csail.mit.edu/albert/bluez-intro/c404.html
where it is also described how to explore services in a remote host; however, what I cannot figure out is how to specify the UUID while connecting the socket. This is something quite straightforward on other contexts, as it happens when using Android libraries; however, with BlueZ I haven't found examples on the web.
Thanks for the help!
Stefano
-- added some details in a reply... don't know if it's right or not; if not, sorry
thanks for your help!
In my post I said I wanted to connect a socket with a specified UUID since I had in mind a function like createRfcommSocketToServiceRecord as can be found in:
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord%28java.util.UUID%29
which returns a socket given a certain UUID. I am developing two softwares, one being the client and the other the server, therefore it's a service I am creating, not a standard one. I publish such service on the server with a specified UUID, and I would like to connect to it from the client. The server is running fine, since with an android platform, exploiting the mentioned createRfcommSocketToServiceRecord method, I am able to connect to the server with the right service.
The example you posted is very clear as well, but unfortunately it is in Python, while (I forgot to point out) I am using Bluez as a C library. I am able to exploit the SDP and inspect services on a remote server; however, when it is the time of setting up the socket, I don't see how to specify the port. I thought about the rc_channel, but as far as I understood it is the bluetooth channel (ranging from 1 to 11 or something similar). Could you please point out Where I should be able to specify the port while creating the socket in the client? And where am I able to find the right port in the complex structure the sdp is dealing with? -- referred to:
http://people.csail.mit.edu/albert/bluez-intro/x604.html
Thanks again for the help!
You don't connect sockets by UUID. You use a socket to connect to remote device and browse its SDP to discover the UUIDs it offers, and map that to a socket port. Here's an example of this process using PyBluez, python wrappers above BlueZ
http://people.csail.mit.edu/albert/bluez-intro/x290.html

Accepting a socket on Windows 7 takes more than a second

Here's what I've done:
I wrote a minimal web server (using Qt, but I don't think it's relevant here).
I'm running it on a legal Windows 7 32-bit.
The problem:
If I make a request with Firefox, IE, Chrome or Safari it takes takes about one second before my server sees that there is a new connection to be accepted.
Clues:
Using other clients (wget, own test client that just opens a socket) than Firefox, IE, Chrome, Safari seeing the new connection is matter of milliseconds.
I installed Apache and tried the clients mentioned above. Serving the request takes ~50ms as expected.
The problem isn't reproducible when running Windows XP (or compiling and running the same code under Linux)
The problem seems to present itself only when connecting to localhost. A friend connected over the Internet and serving the connection was a matter of milliseconds.
Running the server in different ports has no effect on the 1 second latency
Here's what I've tried without luck:
Stopped the Windows Defender service
Stopped the Windows Firewall service
Any ideas? Is this some clever 'security feature' in Windows 7? Why isn't Apache affected? Why are only the browsers affected?
If you're saying "localhost" instead of "127.0.0.1", you're forcing a name lookup before the actual connection attempt, adding delay.
In addition, some browsers, like Firefox 3.5+, don't use the operating system's DNS lookup mechanism, which is why it can have different performance than, say, wget.
You may be running into some automatic proxy discovery problem. In Firefox, you can disable this in Options | Advanced | Network | Settings; select either "No proxy" or give it explicit values. There's also the Internet Properties control panel, which is IE's network settings, but other browsers on Windows may obey settings here, too. Again, disable auto-proxy discovery. This can speed connections outside localhost, too.
For some reason Windows 7 takes 1 second to resolve address localhost regardless of it being in hosts file.
Adding localhost1 to hosts file and using that works around the problem.
When connecting to localhost on a IPv4/IPv6 dual stack host:
A DNS lookup is performed for localhost.
The DNS server (whether IPv6 enabled or not - this doesn't matter) returns both the AAAA record ::1, and the A record 127.0.0.1.
The client first attempts to connect to ::1.
We assume your server program is not IPv6-capable, which is a common case - due to historical reasons, many servers bind their socket to 0.0.0.0 by default rather than [::].
Here an ECONNREFUSED error would be raised for the client. This happens immediately on most platforms; on Windows however, a single call to connect() would try 3 times in 500ms intervals before giving up, hence taking a bit more than one second (See http://stackoverflow.com/q/19440364 for more details).
The client then creates a connection to 127.0.0.1 instead.
This would explain all your clues above:
If you make a request with Firefox, IE, Chrome, Safari or any other IPv6-capable clients, it takes takes about one second trying for ::1 before connecting to 127.0.0.1.
Your own test client just opens a INET socket, so it won't try ::1 at all.
Using a dual-stack server such as Apache, the clients will connect to ::1 happily.
The problem isn't reproducible on Windows XP, of which IPv6 support is not enabled by default.
The problem seems to present itself only when connecting to localhost, as your friend connected with an IPv4-only network.
Running the server in different ports has no effect on the 1 second latency.