Hi
My idea is to make a small B4A server, that must receive an ascii string from a client, pass it to a Bluetooth device, get an answer, and send back it to the client.
Besides the Bluetooth part on which I have no problems, I am now facing difficulties with ServerSocket.
First of all, I have Windows Client-Server C++ programs that work, so I am simply trying to partially reproduce that situation, keeping a Windows executable as the client and making a B4A App as the server. First step for me was to test the communication. So I started with the very simple following app:
Sub Process_Globals
Dim ServerS As ServerSocket
End Sub
Sub Globals
Dim MyIp As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
ServerS.Initialize(10250,"SockEvent") ' port is the same used by the client
MyIp=ServerS.GetMyIP ' this Ip is also hard coded in the client
ToastMessageShow(MyIp,True)
End If
End Sub
Sub Activity_Resume
ServerS.Listen
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SockEvent_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
ToastMessageShow("Connected", True)
Else
Msgbox(LastException.Message, "Error connecting")
End If
ServerS.Listen 'Continue listening to new incoming connections
End Sub
Port and Ip are rigorously the same than those used by the Client-Server Windows programs.
I put the App in a Tablet and close the B4Bridge connection (I don't know whether this has effects or not).
Then I run the App on the Tablet and, after, try to connect with the same Windows client that works with the Windows server, without success.
The Windows client code snippet is:
WSADATA wsaData;
int wsaret=WSAStartup(0x101,&wsaData);
conn=socket(AF_INET,SOCK_STREAM,0);
addr=inet_addr(m_sServerIPAddress.c_str()); // the server IP address
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
In this code "hp" is Always NULL, so the client doesn't connect. Of course, consequently, no event is raised on Android side.
Sorry if this post is not clear. Hope somebody understands, anyway. There is the possibility that I am missing something very "trivial"...
Thanks for your attention
My idea is to make a small B4A server, that must receive an ascii string from a client, pass it to a Bluetooth device, get an answer, and send back it to the client.
Besides the Bluetooth part on which I have no problems, I am now facing difficulties with ServerSocket.
First of all, I have Windows Client-Server C++ programs that work, so I am simply trying to partially reproduce that situation, keeping a Windows executable as the client and making a B4A App as the server. First step for me was to test the communication. So I started with the very simple following app:
Sub Process_Globals
Dim ServerS As ServerSocket
End Sub
Sub Globals
Dim MyIp As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
ServerS.Initialize(10250,"SockEvent") ' port is the same used by the client
MyIp=ServerS.GetMyIP ' this Ip is also hard coded in the client
ToastMessageShow(MyIp,True)
End If
End Sub
Sub Activity_Resume
ServerS.Listen
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SockEvent_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
ToastMessageShow("Connected", True)
Else
Msgbox(LastException.Message, "Error connecting")
End If
ServerS.Listen 'Continue listening to new incoming connections
End Sub
Port and Ip are rigorously the same than those used by the Client-Server Windows programs.
I put the App in a Tablet and close the B4Bridge connection (I don't know whether this has effects or not).
Then I run the App on the Tablet and, after, try to connect with the same Windows client that works with the Windows server, without success.
The Windows client code snippet is:
WSADATA wsaData;
int wsaret=WSAStartup(0x101,&wsaData);
conn=socket(AF_INET,SOCK_STREAM,0);
addr=inet_addr(m_sServerIPAddress.c_str()); // the server IP address
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
In this code "hp" is Always NULL, so the client doesn't connect. Of course, consequently, no event is raised on Android side.
Sorry if this post is not clear. Hope somebody understands, anyway. There is the possibility that I am missing something very "trivial"...
Thanks for your attention