What's Difference Between Ubuntu Server (32bit) and Desktop (32bit) In Socket Programming - sockets

I am working on a server/client based project. I almost finished my server side code.
I develop the server app in EclipseCDT on Ubuntu Desktop, and everything just works fine.
But when deploy my app to a Ubuntu Server (I tried Server 10.04/10.10), the server app can start normally (waiting for connection), but the same client just cannot connect to the server.
I use Socket for receiving and sending data to/from the client.
Peter
P.S.: if I install sudo apt-get install ubuntu-desktop on my server machine, then everything works fine again.
===========================================================================
New Findings from the source code:
LabelStartBlocking:
int newScoketId = ::accept(socketId, 0, 0); // socketId == 3 ::accept is define in socket.h
// waiting for connection
LabelResume: // if new connection coming
// Do something with newSocketId
The behavior difference between Ubuntu Desktop and Server is:
On Ubuntu Desktop version, when the server starts, it is blocked at LabelStartBlocking with the socket routine ::accept; and then if a new connection arrives, the server will resume at LabelResume and create a new socket connection using the return value newSocketId;
However, on Ubuntu Server version, when the server starts, it is also blocked at LabelStartBlocking with the socket routine ::accept, but if a new connection arrives, the server won't resume at LabelResume, and the new socket connection CANNOT be created.
Can you guys help me out?
Peter

Thanks for your attention.
I finally figured it out.
If there are more than one IP addresses for the same hostname (/etc/hosts), the old code will fail.
Example /etc/hosts file:
127.0.0.1 localhost YourHostName
10.50.10.251 YourHostName
I traced the calling stack, and I found that, the IP address (10.50.10.251) passed to the program is translated into hostname, and then later the hostname is translated back to IP address (for binding), but a DIFFERENT one, that's why my server program cannot accept any client connection.
Hope it helps if any others have the similar issue.
Peter

Related

How to expose a Flask local development(default) server to the public on windows server

I have a flask app running on a remote WINDOWS server (this server has a fixed ip address) which is not on my local network. The flask app is used to return some json data. The app works fine when I try to access the data while being logged into the remote server through request module in Python. However, when I try to run the same script on my personal laptop (which is not on the same network as the remote windows server), I get an error. However, when I try to ping the remote server from windows command prompt, I get the answer back. Can somebody tell in which direction should I go? I have no experience with web / api development.
response = requests.get("http://127.0.0.1:5000/product/1)
But instead of the local ip address, if I substitute the remote ip address, I don't get anything back.
Ok, so the problem lied with the remote firewall, it was blocking incoming connections. The moment I switched off the firewall, everything started working.

Test Program in Delphi7 and XP on vmware, failed to connect socket

I try to run program in Delphi7 and XP as virtual machine, the program include client and server and requires socket connections, but every time I try to run it, always showing error message like below.
I have already opened the scktsrvr.exe and I'm sure the port is right at both sides. The program need call the local port.
What confused me is that I tried with same environment and operation with my real PC and it works fine.
So I have no idea why I just can't run the program in a virtual machine. Or is there anything I should do if I want to use socket connections in a virtual machine?
Have found root cause, because of the setting of my client program.
I should set the server IP as local IP of my client program so it can connect the server part.
It's nothing about the virtual machine at all, though I don't need to do previous action in the real machine.
Whatever it has been solved.

getting SocketTimeoutException while using smack 4.1.2 in android to connect to my ejabberd server

I am trying to connect to ejabberd server using smack API 4.1.2 (no asmack) on android device. while running smackClient program , I am getting below error
java.net.SocketTimeOutException:Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms,'abc.example.com:5222' failed because java.net.ConnectionException: Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms
Connection to same ejabberd server using same android device is working fine using xmpp clients like xabber. so Issue is surely with client code I have written. Below is the snippet of my code
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(userName, password)
.setServiceName("abc.example.com")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setSendPresence(true)
.build();
connection = new XMPPTCPConnection(config);
connection.connect();
connection.login(userName, password);
I am missing something in my client code that xabber is having so xabber connection is working from same device using same credential.
Please help
Hard to tell without real IP and names in your example. However, my best guess would be about how the address to your IP server is resolved.
There seems to be discrepancy in your example with server (example.com) and service name in your code (abc.example.com).
My guess it that your client is attempting to connect to another machine that the one the XMPP server is running on.
So, here are the things to check when you have issues with a server not replying:
Check how the address of the domain is resolved. You may need to specify another machine name that the domain. If this is a test domain, there is possibly not a DNS setup, so you may even need to specify server IP (while still configuring the client to use an XMPP domain, that's two different things).
In client, log the IP you are trying to connect to, to make sure this is the one where the server is running.
If server is not on the main domain server, you may even need to do DNS SRV record queries for XMPP C2S service.
For me , it took hours to find the solution.
I forget to turnoff the VPN application(Express VPN) .Network tunneling was the root cause .
And change the Network protocol version properties as below ,
Choose the 1st option (Obtain DNS server address automatically).
My experience: I used following code
DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("desktop-urvfr83");
//DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("192.168.1.3");
InetAddress addr = InetAddress.getByName("192.168.1.3");
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("alir", "111111")
.setHostAddress(addr)
.setResource("phonn")
.setXmppDomain(xmppServiceDomain)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.build();
but it could not connect and produced timeout connection exception. When I disabled windows firewall it worked correctly and connected.

Debugging with XDebug and Netbeans from Windows to Ubuntu remote server

I'm trying to debug a Drupal 7 app with Xdebug. My app resides remotely in a server with Ubuntu running Apache.
In Netabeans, I started a proyect with "Application From Remote Server", connected with SFTP.
In the remote server I have installed Xdebug as zend_extension, also i configured xdebug.remote_connect_back=1, xdebug.remote_autostart=1, etc... I've tried everything with no luck.
The log from Xdebug has entries like this one:
Log opened at 2014-12-24 13:01:31
I: Checking remote connect back address.
I: Remote address found, connecting to 181.175.73.24:9000
E: Time-out connecting to client. :-(
Log closed at 2014-12-24 13:01:32
Based on the log it seems that my computer is not visible from outside on port 9000. But port 9000 in my laptop is opened, listening, with Netbeans, that's what happens when a debug sessions starts.
I think it's a problem with my ISP. My IP is not only for me, so I can't manage it's ports or other configuration. I think my PC is not visible from outside.
So, the question is, how can I avoid this limitation? What could I debug my APP from my computer on a remote server?
Every answer is welcome. Using a program, using a service, both... I tried using pagekite but honestly I couldn't find a configuration that works for me.
Thanks everyone.
PD: I don't want Xdebug alternatives that don't do step by step debugging.
PD2: My Xdebug config is attached.
remote_connect_back won't do it for you, it just tries to connect to the public ip, it's nothing magic.
Can you ssh on the remote server ? You might want to try port forwarding over a reverse ssh tunnel.
Full details from the creator of xdebug:
http://derickrethans.nl/debugging-with-xdebug-and-firewalls.html

Socket -> Connection refused issue

I'm having an issue with Sockets and i can't resolve the problem.
I have 2 distincts machines on the same network. I try to send an object from the first machine to the second.
The second machine is the server, a thread that open a ServerSocket on the port 1456 is running on it. I call the accept() method and it seems to work fine.
When I try to connect to the server from the first machine I receive a ConnectException, Connection refused.
I did a lot of research and found that the port i'm trying to connect to is probably close (firewall issue). I found that the antivirus "avast" blocks the port, so I disable the antivirus and it worked fine ! For 5min...
I uninstalled the antivirus and then it became impossible again to connect to the server. I disabled the windows firewall on both machines. I restarted the machines after each actions.
Does someone have an idea about that?
thanks.