wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Socket program for linux 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 "Socket program for linux" Watch "Socket program for linux" New topic
Author

Socket program for linux

R Sugan
Ranch Hand

Joined: Mar 13, 2009
Posts: 48
Hi,

I tried to develop socket program for asterisk connection.I able to run successfully from remote host in windows.But i didn't able run that same socket program in Linux machine..


This is My Socket code

]



Output:
i am getting this error

Response :Error
Message: Missing action in request
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

It's a bad idea to classes like PrintWriter and BufferedReader when working with sockets as end-of-line characters are platform-dependent: don't println to a socket


[How To Ask Questions On JavaRanch]
R Sugan
Ranch Hand

Joined: Mar 13, 2009
Posts: 48
Hi,

Thanks for your response.I changed my Socket program wr.print instead of wr.println.But am getting the same error message.Please give any solution to solve this problem.That is very helpful to do contious this process.


Regards,
Suganya.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Please post the code you're now using.

What's with the "searcher" Thread? Is that supposed to do something? Where is the variable defined?


Ping & DNS - my free Android networking tools app
R Sugan
Ranch Hand

Joined: Mar 13, 2009
Posts: 48
Hi,

Just name for thread.I tried to develop socket program for asterisk connection.I able to run successfully from remote host in windows.But i didn't able run that same socket program in Linux machine..

This the my java code.




Output:
i am getting this error

Response :Error
Message: Missing action in request
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Just name for thread.

Well, it doesn't do anything, so you might as well delete it, lest someone looks at the code and assumes that it's doing something.

You're still using println with a Socket.

What's with the two newline characters after Timeout and Secret - are you sure that those do the right thing?

It's also a bit weird to do anything this involved in a servlet's init method; is this a load-on-startup servlet? If so, you should use a servlet context listener instead, and start whatever it's supposed to be doing in a separate thread (assuming that it's a long-running operation).
R Sugan
Ranch Hand

Joined: Mar 13, 2009
Posts: 48
Hi,

Thanks for your response.I changed my code print instead of println.The two newline characters after Timeout and Secret this is correct way for sterisk api command.Am getting the same error....


Regards,
Suganya.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
If you're now using print instead of println, then you're in all likelihood missing some newline characters. That's why I asked you to post your current code.

Are you certain that it's OK to send two "Action" commands in a row?

From http://www.voip-info.org/wiki/view/Asterisk+manager+Example%3A+Login:
Don't forget that you have to end your request with \r\n\r\n (two CrLfs), that's ascii characters 13, 10, 13 and 10 successively.
R Sugan
Ranch Hand

Joined: Mar 13, 2009
Posts: 48
Hi,
This is My changed code.But am also getting the same error....

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
I'd be surprised if it was possible to send command without separating them by a newline character, or some such delimiter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket program for linux