Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ObexListenerContext(Stream rs) for Android file transfer #356

Open
wants to merge 2 commits into
base: obex-development
Choose a base branch
from

Conversation

DavidR5
Copy link

@DavidR5 DavidR5 commented Oct 25, 2023

Added ObexListenerContext(Stream rs) for file transfer between Windows and Android due to System.Net.Sockets not being compatible with Android sockets.
added ContentMd5 ObexHeader to facilitate sending Md5 checksum to destination with file.

Copy link
Member

@peterfoot peterfoot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few changes to the main branch to support user headers as described in my comments. Therefore I think rather than define ContentMd5 in the ObexHeader enum you should set it with one of the new user values e.g. User0 for 0x30.

InTheHand.Net.Obex/ObexHeader.cs Outdated Show resolved Hide resolved
InTheHand.Net.Obex/ObexListenerContext.cs Show resolved Hide resolved
InTheHand.Net.Obex/ObexListenerContext.cs Show resolved Hide resolved
InTheHand.Net.Obex/ObexWebRequest.cs Outdated Show resolved Hide resolved
@@ -1038,8 +1050,16 @@ public override WebResponse GetResponse()
ObexStatusCode status;
MemoryStream ms = new MemoryStream();
WebHeaderCollection responseHeaders = new WebHeaderCollection();
// Added David Rodgers to facilitate sending an Md5 checksum in the header
// could be expanded to loop through Headers and add any headers that are set by the user
if (Headers["ContentMd5"] != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to add the existing request header here? - because the responseHeaders should contain the headers as sent by the remote device along with the retrieved file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When sending the file I set the user defined header request.Headers.Add("ContentMd5", md5); ("ContentMd5" would change to "User0" with your new changes) before calling request.GetResponse(); The call to GetResponse() then creates responseHeaders as a new WebHeaderCollection() instance effectively wiping out the previously set user defined header. Other headers are added in ObexWebRequest:DoPut(); With your new user defined headers where would we set them when sending a file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will wait until I find out how to set a user defined header so I can implement and test before resubmitting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have not commented about public ObexListenerContext(Stream rs) with a stream parameter instead of socket, what are your thoughts about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I've been distracted and forgot to follow up on this. Now that the listener can work from either a stream or a socket, I don't think the public constructor is needed because this can be created through the normal listener flow.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see where you test for socket == null in ObexListenerContext at line 257 and assign stream on line 259 but this is not used. Line 283 says "// call to stream implementation to go here" so there is no ObexListenerContext returned. So this does not seem to be any further ahead with regard to getting the ObexListenerContext "through the normal listener flow". My other issue is that I have to use BluetoothListener rather than ObexListener because I need to set a custom service GUID. It would be great if we could pass a custom GUID to the BluetoothListener constructor. This is why I created the public ObexListenerContext constructor which took a stream argument. I want to use ObexListenerContext but also need a custom service GUID.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, then it should expose the public constructor for those cases. There is definitely scope for more flexibility in the listener so it can support custom services

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you be making changes to support custom services and when would you expect to include them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think based on time available to this at the moment we assume that it won't happen soon. It'll possibly require work to both the BluetoothListener and ObexListener to fully support.

@DavidR5
Copy link
Author

DavidR5 commented Nov 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants