Wininet HttpSendRequest over GPRS - Windows Mobile Development and Hacking General

Hi
I wondered if anyone has any tips on using Wininet over GPRS. I'm currenct using eVc 4 to write an application that sends data to a web server using the Wininet HttpSendRequest or HttpSendRequestEx Functions. The problem I get is when I try to send more than about 10k of data I get a server timeout using the GPRS connection but everything seems fine when I have the XDAii in the cradle.
Ok so the problem seems to be GPRS being slow and unreliable but I have experimented with sending the data in 1k chunks and the problem comes when trying to end the http request with HttpEndRequest. I have checked the server timeouts on my IIS server and they are all set to 15 minutes.
Does anyone have any clues?

This is the code I use to do a similar thing with a photo which works quite well
Are you setting the response to nothing?
GPRS is very unreliable but I have managed to send 70k files over it.
==========
Private Function FileUpload(ByVal sURL As String, ByVal sFile As String) As String
On Error GoTo eh
Dim binReader As BinaryReader
Dim byteArray() As Byte
binReader = New BinaryReader(File.OpenRead(sFile))
byteArray = binReader.ReadBytes(binReader.BaseStream.Length)
Dim httpURI As New Uri(sURL & sFile)
Dim httpRequest As HttpWebRequest = httpRequest.Create(httpURI)
httpRequest.Method = "POST"
httpRequest.ContentLength = binReader.BaseStream.Length
Dim httpReqStream As Stream
httpReqStream = httpRequest.GetRequestStream
httpReqStream.Write(byteArray, 0, byteArray.Length)
httpReqStream.Close()
Dim httpResponse As HttpWebResponse
httpResponse = httpRequest.GetResponse
Dim sResponse As String
sResponse = CStr(httpResponse.StatusDescription)
FileUpload = "OK"
httpResponse.Close()
binReader.Close()
httpURI = Nothing
httpRequest = Nothing
httpReqStream = Nothing
binReader = Nothing
httpResponse = Nothing
byteArray = Nothing
Exit Function
eh:
MsgBox(Err.Description)
binReader.Close()
FileUpload = "ERROR"
httpURI = Nothing
httpRequest = Nothing
httpReqStream = Nothing
binReader = Nothing
httpResponse = Nothing
End Function
===================

My code seems to be fine as when I used my mates Vodafone sim in the Xda ii I was able to send a 40k file straight away. It seems there is a limit somewhere around the 8-9k mark in the O2 gprs apn. I have to now get on to 02 and find out how they will let me send more than 8k at a time.

There is a problem with O2. They had to give me a new username and password to log onto their network, which has different privileges, to get around it.
Good Luck

Related

GPRS Connection Issues

Hi All,
My app is required to update certain information to my server every 15mins or so. This data is being successfully posted, however on reviewing my phone bill, the code is forcing a new GPRS connection with each post.
I use the ConnectionManager API to get a handle to the optimal/current connection:
Code:
DWORD dwCurrentStatus;
ConnMgrConnectionStatus(hConnection, &dwCurrentStatus);
if (dwCurrentStatus != CONNMGR_STATUS_CONNECTED){
ConnMgrEstablishConnectionSync(&sCI, &hConnection, 30000, &dwStatus);
}
// Make outgoing internet connection.
hInternetSession = InternetOpen(TEXT("My App"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
// Connect to the server
hServerSession = InternetConnect(hInternetSession, szServer, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
if(hInternetSession == NULL || hServerSession == NULL){
return false;
}
After each post I close the internet handle ( I am fairly sure this shouldn't drop the GPRS connection):
Code:
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
On application SHUTDOWN I allow the connection to close:
Code:
ConnMgrReleaseConnection(hConnection, 0);
if(hConnection){
hConnection = NULL;
}
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
Has anyone else had similar problems or is aware of what I am doing wrong?
Cheers
gprs connection
i have a small app that changes gprs connection when one of them is down, but i have found that the connmgrreleaseconnection call does not work, and the current connection will not die, you may have the same problem

Send a file from server to client via stream

hi,
I currently have a client server app which passes back and forth String data and it works great. but now i have the need to send non text files ie images from server to client (PPC). It is all based on system.net.sockets.
The client is making a request via the following
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(lData)
lnetworkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(ltcpClient.ReceiveBufferSize) As Byte
lnetworkStream.Read(bytes, 0, CInt(ltcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, bytes.Length)
The server code is responding via the following .
Private Sub sendmessage(ByVal s As Socket, ByVal message As String)
Buffer = New [Byte](message.Length + 1) {}
Dim length As Integer = ASCII.GetBytes(message, 0, message.Length, Buffer, 0)
s.Send(Buffer, length, 0)
End Sub 'sendmessag
Can any one one help, i can't seem to find any help on sending and receiving files via sockets.
thanks in advance

SMS to Email Address programatically?

I did a search in the forum, and didn't see if this is mentioned, so forgive me if this has been discussed.
I am trying to programatically send an SMS to a normal email address... and I know the phone can do it (AT&T Tilt, AT&T service), as I can do it manually. My first approach (as to not start monkeying around with the MAPI stuff) is to try the SMS API (sms.h and sms.lib). I am trying to use the SmsSendMessage function. My code works great for messages to other phones, but fails with the very informative return code of E_FAIL when sending to a "normal" email address.
Is there a trick or a setting that I am missing?
Here is a code sample of what I am trying to do:
Code:
BOOL CSMSSender::Send( wchar_t *message )
{
if( message == NULL )
{
return FALSE;
}
SMS_HANDLE smsHandle;
SMS_ADDRESS source;
SMS_ADDRESS dest;
TEXT_PROVIDER_SPECIFIC_DATA textData;
SMS_MESSAGE_ID messageId;
HRESULT result = S_OK;
BOOL retVal = TRUE;
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return FALSE;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, GetSmsAddr( ), SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) message,
_tcslen( message ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );
if( result != S_OK )
{
retVal = FALSE;
goto EXIT;
}
EXIT:
result = SmsClose( smsHandle );
if( result != S_OK )
{
retVal = FALSE;
}
return retVal;
}
You can probably guess that GetSmsAddr( ) returns a wchar_t * that is the address I am trying to send it to. When it is a phone number, works swimmingly, when it is a "normal" email address, it fails. This is, of course, a snippet of a much larger system, but the only SMS specific stuff, and the stuff that gives me the problems. So, if you wonder "why did he do it this way", probably stuff missing that would make it more clear.
If the answer is to go swimming in the mess that is MAPI, then so be it... but would like to know if there is an easier answer before I put on my trunks...
Take Care,
Wicked96SS
Found the solution... I feel dumb... It is actually pretty easy. The provider is the one that does the conversion from SMS to "normal" email. And you have to send the SMS to the email gateway. The SMS has to be specially formatted. Here is a non comprehensive list of the formats expected by certain vendors:
Format (Carrier;SMS to Email Gateway Number;Text Format)
AT&T (Formerly Cingular) USA;111 or 121;emailaddress (subject) text
CTI (Argentina);6425;emailaddress (subject) text
Swisscom Mobile AG (only Switzerland);555;<emailaddress> <subject>/<text>
T-Mobile Austria http://t-mobile.at;6761;<emailaddress> <text>
T-Mobile (USA);500;<emailaddress> / <subject> / <text>
Anyhow, still looking for Verizon and some others, but i am sure they are simple.
So, if configured like that, and sent to the correct number, I do get SMS messages to normal email accounts.
Code snippet for AT&T
Code:
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return SMS_INIT_FAILED;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, L"111", SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
std::wstring body;
body = L"[email protected](Hi!)Here is the body";
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) body.c_str( ),
_tcslen( body.c_str( ) ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );
Question on Normal Emails
I found your posting and it works great for sending sms messages to cell phone emails.
I found this link that shows the other gateways you were looking for.
http://en.wikipedia.org/wiki/SMS_gateways
My question is did you ever get this to work to send emails to network email address like [email protected]
let me know if you have any suggestions.
Thanks in Advance
ColoradoGene
hello ColoradoGene! Sorry for the time it took to respond, but yes, I have been able to send SMS messages to email addresses... the message has to be formatted correctly. The source code in my post (#2) will work for AT&T.
What problems are you actually having?

PPC with Windows Mobile as Server

I have tried for some hours now to catch the problem, nowhere are good resources to read.
I have a server application running on my phone (Windows Mobile 6.1)
Binding the TCP Listener to 127.0.0.1ORT does work, if I type the URL from within the device.
Then I tried to connect via WIFI. At first: All WiFi Settings are correct, I know all IPs and pings are possible ... BUT: When I try to access the server from within the wifi network I don't get through. I've bound the listener for testing purposes to 127.0.0.1 and to the IP of my Wifi card. but nothing helped. Is there a kind of firewall or why can't I use a socket connection from PC to PPC?
This should work. I've create a remote-control program via TCP/IP and there were no issues.
Can you post the code for Bind / Listen?
radhoo said:
Can you post the code for Bind / Listen?
Click to expand...
Click to collapse
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Provided your code is good, maybe check if the socket is actually listening, there's netstat tool in dotFred's task manager: http://www.dotfred.net/TaskMgr.htm
Furthermore, you can see if the traffic ever reaches your PPC with hSniffer:
http://winm-soft.atspace.com/
You don't seem to be checking any of the return values.
Have you done that?
You might be facing different conditions than when you bind to the loopback adapter.
theq86 said:
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Click to expand...
Click to collapse
try other different port rather than http port = 80
mobile phone not design to be a web server.

Samsung devices not sending IPv6 Multicast datagrams

Hey, sorry if this is in the wrong forum, but I was not exactly sure where to post this.
I'm facing problems sending UDP packets over IPv6 multicast addresses on Galaxy devices.
Particularly, I want to send a Wake-on-LAN Magic Packet over IPv6 to wake up a PC in a different network. That PC is only reachable from outside via IPv6. Since it doesn't have an IP address when it's turned off, I can't send the Magic Packet directly to the computer and need to broadcast it over the network. I'm pretty new to IPv6, so I had to do some research on how to broadcast packets over IPv6 first and I'm not quite sure, if I'm doing everything correctly.
So, let's suppose the network the PC is connected to has the following network prefix:
2a02:123:4567:89ab::/64
According to RFC3306, I can use that prefix to derive a global multicast address, which would be the following:
ff3e:40:2a02:123:4567:89ab:0:0
Packets sent to this address should reach all devices on the network.
I wrote a small method to send a UDP packet to that multicast IP address and checked with Wireshark, if the packets were received or not.
When I run the method in a regular Java application, everything works fine and the packet is received by all devices on the network. When I use the same method in an Android app, I notice a strange behavior. If I send the packet from Non-Samsung devices (e.g. Blackview BV2000s) there are no problems. But from Samsung devices (Galaxy S3, S6 and Note 4 to be precise), the packet is not received by the PC. I think, the devices don't even send out the packet. Strange enough, if I address the PC directly with it's unicast address (e.g. 2a02:123:4567:89ab:cdef:fedc:ba98:7654), the packet is sent and received without any problems. So the problem only occurs on Samsung devices and only when sending to multicast addresses.
I'm using the following method to send the packet:
Java:
public void sendMagicPacket(String host, int port, String macAddress) {
try {
InetAddress address = InetAddress.getByName(host);
String[] macData = macAddress.split("\\:");
byte[] mac = new byte[6];
for (int i = 0; i < 6; i++) {
mac[i] = (byte)Short.parseShort(macData[i], 16);
}
byte[] magic = new byte [102];
for (int i = 0; i < 6; i++) {
magic[i] = (byte)0xff;
}
for (int i = 6; i < 102; i++) {
magic[i] = mac[i%6];
}
DatagramPacket packet = new DatagramPacket(magic, magic.length, address, port);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
} catch (final Exception e) {}
}
I'm pretty sure there is nothing wrong with the method itself, but am I missing something Android specific? Is sending to IPv6 multicast addresses not supported by Samsung devices or is it a bug? I'm pretty helpless and have no idea how to solve this problem. I hope someone can help me with this. :fingers-crossed:

Categories

Resources