aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Communication between different protocols Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Communication between different protocols" Watch "Communication between different protocols" New topic
Author

Communication between different protocols

feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
How can I allow a server with socket connection to communicate with a client with HttpConnection bidirectional?Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
If the client speaks HTTP, then the server had better speak HTTP as well, or they won't be able to communicate. What kind of process is listening on the server side?


Ping & DNS - my free Android networking tools app
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I cannot make the server speaks HTTP since it is using J2me which supports only ServerSocketConnection but not Http. What do you mean by what kind of process?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
By process I mean the piece of code that is listening on the server port. Do you have control over that? If so, you could implement a simple HTTP server.

But having a mobile device as a listener seems a somewhat strange thing to do; what exactly are you trying to do?
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
The server has a socket connection
And the client which is also a mobile has an HTTP connection


Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
HTTP also makes use of TCP and IP layers of course, but that Socket which lives in TCP and IP layers doesn't know HTTP. Write a socket program to connect to googles http server, you can connect, but would have to do a lot of additional work(implement relevant HTTP functionality) to pull off a meaningful conversation.

The purpose of a protocol is so two or more machines can talk. If they are speaking different languages they can't communicate, not even with hand gestures.

Did you write both client and server? if so change one to match the others protocol, or can at least add on to it doing something like the adapter pattern if you want to keep the current protocol intact.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
Yes I want to know how to write the adapter pattern to allow the socket connection understands HTTP requests. Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Maybe these articles get you started: How Java Web Servers Work and How Servlet Containers Work
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
Thank you for the good links but what I need is protocol adapter ? That I didnot find it in the provided links!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Not sure what you mean by adapter. To me it looks like ServerSocketConnection provides just the socket connection - whatever protocol you want to run on top of it you need to implement yourself (possibly using HTTP server code found elsewhere on the web).

I'd still be curious what the big picture is of what you're trying to do. A better alternative than to try to run an HTTP server on a mobile device may be available.
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I didnot find any Http server on j2me. If you find one the problem will be solved .
Regarding the servletsocket connection . How it can be implemented on mobile device that acts as a server and can only speaks socket connection while it should communicate with clients that sends and receives http messages using HttpConnection?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Time for some clarifications, I think.
I didnot find any Http server on j2me.

Right. Not even J2SE used to contain an HTTP server, so a resource-limited environment like J2ME is much less likely to contain one.

If you find one the problem will be solved.

No, if YOU find one the problem will be solved. If you don't find one, then you'll need to implement one, or come up with some other communication scheme that doesn't require one.

And actually, since there is no HTTP server, and you seem to have problems finding or implementing one, the question is: why do you want to use HTTP at all? This goes back to my question of what it actually is that you're trying to do; you still haven't old us.

Regarding the servletsocket connection . How it can be implemented on mobile device that acts as a server and can only speaks socket connection while it should communicate with clients that sends and receives http messages using HttpConnection?

What kind of client is this? Why does it need to use HTTP, and not some other protocol for which you might have an easier time implementing a server? And most importantly: What kind of use case is this where a client needs to contact a mobile device? Are you sure there isn't a better way to make this communication work? Implementing a client is generally much simpler than implementing a server.
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
Fine, I need Both client and server to speak HTTP since HTTPConnection of J2ME has powerful methods for parsing and extracting the HTTP header and body message.
However as I mentioned before J2ME does only support socket connections for mobile servers to listens to incomming requests.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
I'm sorry, but that doesn't make sense. In essence you're saying "I need to use HTTP because J2ME handles HTTP well" but it seems that J2ME doesn't handle HTTP at all (just raw sockets) and you seem to have trouble implementing it. That just doesn't add up.

Let me ask again: What is the underlying problem you're trying to solve? What kind of client wants to access the J2ME device, and why? Is it certain that the client *can* access to the J2ME device? Those generally don't have IP addresses that are accessible from everywhere on the net, as far as I know.
 
Consider Paul's rocket mass heater.
 
subject: Communication between different protocols