Connecting modem via java

Closed Thread

Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Connecting modem via java

 
0
  #1
Nov 18th, 2004
Hi
I have a problem in connecting modem with another modem through PSTN. i want the solution in java code

i want this connection to upload file from remote pc to my local pc

i want to develope the whole application in java

plz help me out as early as possible : :-|
Quick reply to this message  
Join Date: Dec 2003
Posts: 6,439
Reputation: DMR will become famous soon enough DMR will become famous soon enough 
Solved Threads: 364
Team Colleague
DMR's Avatar
DMR DMR is offline Offline
Wombat At Large

Re: Connecting modem via java

 
0
  #2
Nov 18th, 2004
You should really give us a more specific descripition of your needs, but overall this question sounds more suited to the Java programming forum.

Moving there now...
"May the Wombat of Happiness snuffle through your underbrush."
- Ancient Aborigine blessing


Please do not contact me by email or PM for help. We're all volunteers here, and only have so much free time to dedicate to our efforts.

However, if I've been working on a thread with you already, and seem to have "forgotten" your thread, please do send me a message. I try not to let things slip through the cracks, but it does happen sometimes.
Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

 
0
  #3
Dec 20th, 2004
hi
i have connected two pcs using modem via PSTN using comm api in follwing sequences.

1) My local modem calls to the Remote modem using the ATDT 235 command
2) on remote side one program continuosly listens to the incoming call.
3) After that my local modem detects the "CONNECT 9600" response.
4) Also my remote modem detects the same response it waits for some time and start transmitting data.
5) But my local modem is unable to receive some starting bytes and after some bytes it has receive it stops the receiving bytes.
6) But when i terminate the remote program my local modem receives the whole set of bytes.

Remote modem - DLINK DFM-562E++
Local Modem - DLINK DFM-560ES

THANKS IN ADVANCE
Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Connecting modem via java

 
0
  #4
Dec 20th, 2004
Post the relevant parts of your code. Sounds like you are forgetting to flush some buffers.
Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

 
0
  #5
Dec 20th, 2004
This is my Dialup.java running at server side

  1. import java.io.*;
  2. import java.util.*;
  3. import javax.comm.*;
  4.  
  5. public class Dialup implements Runnable,SerialPortEventListener
  6. {
  7.  
  8. static CommPortIdentifier portId;
  9. static Enumeration portList;
  10.  
  11. InputStream inputStream;
  12. OutputStream outputStream;
  13. SerialPort serialPort;
  14. Thread dialupThread;
  15. String telNo;
  16. String dialCommand;
  17. String initCommand;
  18. String line;
  19. static BufferedReader bos;
  20. static OutputStream fos = null;
  21. static FileOutputStream output = null;
  22. static DataOutputStream dOut = null;
  23. boolean flag = false;
  24. int conCount = 0;
  25.  
  26. public static void main(String[] args)
  27. {
  28. try
  29. {
  30. fos = new FileOutputStream("dem.txt",true);
  31. bos = new BufferedReader(new FileReader("dem.txt"));
  32. output = new FileOutputStream("abc.txt",true);
  33. dOut = new DataOutputStream(output);
  34. }catch(Exception e)
  35. {}
  36.  
  37. if( args.length != 1 )
  38. {
  39. System.err.println("Usage: Dialup ");
  40. return;
  41. }
  42. portList = CommPortIdentifier.getPortIdentifiers();
  43.  
  44. while (portList.hasMoreElements())
  45. {
  46. portId = (CommPortIdentifier) portList.nextElement();
  47. if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
  48. {
  49. if (portId.getName().equals("COM1"))
  50. {
  51. Dialup dialer = new Dialup(args[0]);
  52. }
  53. }
  54. }
  55.  
  56. }
  57.  
  58. public Dialup(String telNo)
  59. {
  60. // this.dialCommand = "&F&K3%E2%C0W2\\N3+MS=12,1,28000,46667";
  61. this.telNo = telNo;
  62. this.dialCommand = "ATDT"+telNo+"\r";
  63. initCommand = "&F&K3%E2%C0W2\\N3+MS=12,1,28000,46667\r";
  64. // this.dialCommand = "AT&C0&W0\r";
  65. // this.dialCommand = "ATO0";
  66. // this.dialCommand = "ATO0";
  67. try
  68. {
  69. serialPort = (SerialPort) portId.open("DialUp", 2000);
  70. }
  71. catch (PortInUseException e)
  72. {
  73. }
  74.  
  75. try
  76. {
  77. inputStream = serialPort.getInputStream();
  78. outputStream = serialPort.getOutputStream();
  79. }
  80. catch (IOException e)
  81. {
  82. System.out.println(" Hell " + e);
  83. }
  84.  
  85. try
  86. {
  87. serialPort.addEventListener(this);
  88. }
  89. catch (TooManyListenersException e) {
  90. }
  91.  
  92.  
  93. portList = CommPortIdentifier.getPortIdentifiers();
  94. while (portList.hasMoreElements())
  95. {
  96. portId = (CommPortIdentifier) portList.nextElement();
  97.  
  98. if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
  99. {
  100.  
  101. if (portId.getName().equals("COM1"))
  102. {
  103. // System.out.println(getInputBufferSize());
  104. // try
  105. // {
  106. //serialPort = (SerialPort) portId.open("writereadApp", 2100);
  107. //System.out.println("Opened the port for writing: " + portId.getName());
  108. // }
  109. // catch (PortInUseException e) {System.out.println("IN USE ---- " + e);}
  110.  
  111. try
  112. {
  113. serialPort.setSerialPortParams(9600,
  114. SerialPort.DATABITS_8,
  115. SerialPort.STOPBITS_1,
  116. SerialPort.PARITY_NONE);
  117. }
  118. catch (UnsupportedCommOperationException e)
  119. {
  120. System.out.println("UnsupportedCommOperationException, Could not write to the port: " + e);
  121. }
  122. try
  123. {
  124. outputStream = serialPort.getOutputStream();
  125. inputStream = serialPort.getInputStream();
  126. }
  127. catch (IOException e) {System.out.print(e);}
  128.  
  129. /* try
  130. {
  131. serialPort.addEventListener(this);
  132. }
  133. catch (TooManyListenersException e) {System.out.println("TOOO " + e);}
  134. */
  135. serialPort.notifyOnDataAvailable(true);
  136. serialPort.notifyOnCarrierDetect(true);
  137. serialPort.notifyOnDataAvailable(true);
  138. serialPort.notifyOnBreakInterrupt(true);
  139. serialPort.notifyOnCTS(true);
  140. serialPort.notifyOnDSR(true);
  141. serialPort.notifyOnFramingError(true);
  142. serialPort.notifyOnOutputEmpty(true);
  143. serialPort.notifyOnOverrunError(true);
  144. serialPort.notifyOnParityError(true);
  145. serialPort.notifyOnRingIndicator(true);
  146. }
  147.  
  148. }
  149. }
  150. dialupThread = new Thread(this);
  151. dialupThread.start();
  152. }
  153.  
  154. public void run()
  155. {
  156. while(true)
  157. {
  158. if(conCount == 0)
  159. {
  160. try
  161. {
  162. if( !serialPort.isCD() )
  163. {
  164. // outputStream.write(initCommand.getBytes());
  165. System.err.println("Try to connect ...");
  166. outputStream.write(dialCommand.getBytes());
  167. }
  168. Thread.sleep(60000);
  169. /*for(int i=0; i < 10; i++)
  170. {
  171. outputStream.write("Ram".getBytes());
  172. System.out.print("Ram");
  173. }*/
  174. }
  175. catch(Exception ex)
  176. {
  177. System.err.println("Failed to write message");
  178. }
  179. }
  180. }
  181. }
  182.  
  183. public void serialEvent(SerialPortEvent event)
  184. {
  185. switch(event.getEventType())
  186. {
  187. case SerialPortEvent.OE:
  188. case SerialPortEvent.FE:
  189. case SerialPortEvent.PE:
  190. case SerialPortEvent.DSR:
  191. System.out.println("Data Set Ready.");
  192. break;
  193. case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
  194. System.out.println("Ignored event");
  195. break;
  196.  
  197. case SerialPortEvent.BI:
  198. System.out.println("Break Interrupt");
  199. break;
  200.  
  201. case SerialPortEvent.CTS:
  202. System.out.println("Clear to send");
  203. break;
  204.  
  205.  
  206. case SerialPortEvent.RI:
  207. if( event.getNewValue() )
  208. {
  209. System.out.println("Ring Indicator On");
  210. }
  211. else
  212. {
  213. System.out.println("Ring Indicator Off");
  214. }
  215. break;
  216.  
  217. case SerialPortEvent.CD:
  218. if( event.getNewValue() )
  219. {
  220. System.out.println("Connected");
  221. conCount = conCount + 1;
  222. flag = true;
  223. }
  224. else
  225. {
  226. System.out.println("Disconnected");
  227. }
  228. break;
  229.  
  230. case SerialPortEvent.DATA_AVAILABLE:
  231. handleData();
  232. break;
  233. }
  234. }
  235.  
  236. public void handleData()
  237. {
  238. try
  239. {
  240. int avail = inputStream.available();
  241. byte[] response = new byte[avail];
  242. StringBuffer strbuf = new StringBuffer();
  243. inputStream.read(response, 0, avail);
  244. for (int i = 0; i < avail; i++)
  245. {
  246. if(!flag)
  247. {
  248. fos.write((char)response[i]);
  249. }
  250. }
  251. /* while((line = bos.readLine())!=null)
  252. {
  253. if(line.equals("CONNECT 9600"))
  254. {
  255. flag = true;
  256. dOut.flush();
  257. }
  258. }
  259. */ if(flag)
  260. {
  261. inputStream.read(response, 0, avail);
  262. for (int i = 0; i < avail; i++)
  263. {
  264. Thread.sleep(5);
  265. output.write((char)response[i]);
  266. System.out.print((char)response[i]);
  267. }
  268. }
  269. }catch(IOException ie1){System.out.println("File " +ie1);}
  270. catch(InterruptedException in){System.out.println("Interrupt " +in);}
  271.  
  272. }
  273. }


this is my client side code
  1. import java.io.*;
  2. import java.util.*;
  3. import javax.comm.*;
  4. public class ReadDemo1 implements SerialPortEventListener
  5. {
  6. static Enumeration portList;
  7. static CommPortIdentifier portId;
  8. static String output = "";
  9. SerialPort serialPort;
  10. static OutputStream outputStream;
  11. static InputStream inputStream;
  12. static String dialCommand;
  13. Thread readThread;
  14. int temp = 0;
  15.  
  16. //*************************
  17. StringBuffer inputBuffer = new StringBuffer();
  18. DataOutputStream dout = null;
  19. OutputStream fos = null;
  20. String line;
  21. int ch;
  22. BufferedReader bos = null;
  23. int newData = 0;
  24. boolean writeFlag = false;
  25. FileInputStream fis = null;
  26.  
  27. public static void main(String[] args)
  28. {
  29.  
  30.  
  31. int ch;
  32. InputStream fis;
  33. byte[] size = null;
  34. int count = 0;
  35.  
  36. ReadDemo1 readObject = new ReadDemo1();
  37. /* try
  38. {
  39. // outputStream.write("ATM0L1S0=1&D2&C1S2=36S95=46&Q5\r".getBytes());
  40. outputStream.write("AT\\K0\r".getBytes());
  41. }catch(IOException ioe)
  42. {
  43. System.out.println("IOException" + ioe);
  44. }
  45. */
  46. }
  47.  
  48. void Write(byte[] commandToSend)
  49. {
  50. try
  51. {
  52. outputStream.write(commandToSend);
  53. System.out.println("Successfully Written: " + commandToSend);
  54. }
  55. catch (IOException e) {System.out.println("IO Exception Occured: " + e);}
  56. }
  57. void closePort()
  58. {
  59. serialPort.close();
  60. System.out.print("Serial port closed.");
  61. }
  62.  
  63.  
  64. public ReadDemo1()
  65. {
  66.  
  67. portList = CommPortIdentifier.getPortIdentifiers();
  68. while (portList.hasMoreElements())
  69. {
  70. portId = (CommPortIdentifier) portList.nextElement();
  71.  
  72. if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
  73. {
  74.  
  75. if (portId.getName().equals("COM1"))
  76. {
  77. try
  78. {
  79. serialPort = (SerialPort) portId.open("writereadApp", 2000);
  80. System.out.println("Opened the port for writing: " + portId.getName());
  81. }
  82. catch (PortInUseException e) {System.out.print(e);}
  83.  
  84. try
  85. {
  86. serialPort.setSerialPortParams(9600,
  87. SerialPort.DATABITS_8,
  88. SerialPort.STOPBITS_1,
  89. SerialPort.PARITY_NONE);
  90. }
  91. catch (UnsupportedCommOperationException e) {System.out.println("UnsupportedCommOperationException, Could not write to the port: " + e);}
  92. try
  93. {
  94. outputStream = serialPort.getOutputStream();
  95. inputStream = serialPort.getInputStream();
  96. }
  97. catch (IOException e) {System.out.print(e);}
  98.  
  99. try
  100. {
  101. serialPort.addEventListener(this);
  102. }
  103. catch (TooManyListenersException e) {System.out.print(e);}
  104.  
  105. serialPort.notifyOnDataAvailable(true);
  106. serialPort.notifyOnCarrierDetect(true);
  107. serialPort.notifyOnDataAvailable(true);
  108. serialPort.notifyOnBreakInterrupt(true);
  109. serialPort.notifyOnCTS(true);
  110. serialPort.notifyOnDSR(true);
  111. serialPort.notifyOnFramingError(true);
  112. serialPort.notifyOnOutputEmpty(true);
  113. serialPort.notifyOnOverrunError(true);
  114. serialPort.notifyOnParityError(true);
  115. serialPort.notifyOnRingIndicator(true);
  116. }
  117. }
  118. }
  119. }
  120.  
  121.  
  122.  
  123. public void serialEvent(SerialPortEvent event)
  124. {
  125. switch(event.getEventType())
  126. {
  127. case SerialPortEvent.DATA_AVAILABLE:
  128. handleData();
  129. break;
  130. case SerialPortEvent.OE:
  131. case SerialPortEvent.FE:
  132. case SerialPortEvent.PE:
  133. case SerialPortEvent.DSR:
  134. System.out.println("Data set ready.");
  135. break;
  136. case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
  137. System.out.println("Ignored event");
  138. break;
  139. case SerialPortEvent.BI:
  140. System.out.println("Break Interrupt");
  141. break;
  142. case SerialPortEvent.CTS:
  143. System.out.println("Clear to send");
  144. break;
  145. case SerialPortEvent.RI:
  146. System.out.println("Pick up the receiver.");
  147. if( event.getNewValue() )
  148. {
  149. System.out.println("Ring Indicator On");
  150. }
  151. else
  152. {
  153. System.out.println("Ring Indicator Off");
  154. }
  155. break;
  156. case SerialPortEvent.CD:
  157. if( event.getNewValue() )
  158. {
  159. System.out.println("Connected");
  160. try
  161. {
  162. Thread.sleep(120000);
  163. while((ch = fis.read()) != -1)
  164. {
  165. outputStream.write(ch);
  166. // Thread.sleep(15);
  167. System.out.print((char)ch);
  168. }
  169.  
  170. Thread.sleep(180000);
  171. }catch(Exception e)
  172. {
  173. System.out.println(e);
  174. }
  175. }
  176. else
  177. {
  178. System.out.println("Disconnected");
  179. System.exit(0);
  180. }
  181. break;
  182. }
  183. }
  184. public void handleData()
  185. {
  186. // System.out.println(writeFlag);
  187. System.out.print("Inside serial event");
  188. try
  189. {
  190. fis = new FileInputStream("abc.txt");
  191. }catch(FileNotFoundException fne)
  192. {
  193. System.out.println("File Does not exists.");
  194. }
  195. try
  196. {
  197. fos = new FileOutputStream("rmn.txt",true);
  198. bos = new BufferedReader(new FileReader("rmn.txt"));
  199. dout = new DataOutputStream(fos);
  200. int avail = inputStream.available();
  201. byte[] response = new byte[avail];
  202. StringBuffer strbuf = new StringBuffer();
  203. inputStream.read(response, 0, avail);
  204. for (int i = 0; i < avail; i++)
  205. {
  206. fos.write((char)response[i]);
  207. }
  208. if(!writeFlag)
  209. {
  210. while((line = bos.readLine())!=null)
  211. {
  212. // dout.flush();
  213. if(line.equals("CONNECT 9600/ARQ"))
  214. {
  215. writeFlag = true;
  216. System.out.println("connect");
  217. }
  218. }
  219. }
  220. if(writeFlag)
  221. {
  222.  
  223. }
  224. }catch(IOException ie1){System.out.println("File " +ie1);}
  225. // catch(InterruptedException ie1){System.out.println("File " +ie1);}
  226. }
  227. }
Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Connecting modem via java

 
0
  #6
Dec 21st, 2004
Like I suspected you're not flushing any of your Streams, that's BAD.
I've not checked if you're properly closing them, look for that as well.
Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: atul_manaskar is an unknown quantity at this point 
Solved Threads: 0
atul_manaskar atul_manaskar is offline Offline
Newbie Poster

Re: Connecting modem via java

 
0
  #7
Dec 22nd, 2004
hi
can u plz tell me the sequence in which after the modem get connected i should flush the streams while transferring data from one end to other.

Modem stop receiving bytes after the follwing events
Data set Ready
Break Interrupt
Quick reply to this message  
Join Date: Mar 2005
Posts: 1
Reputation: danny_ is an unknown quantity at this point 
Solved Threads: 0
danny_ danny_ is offline Offline
Newbie Poster

Re: Connecting modem via java

 
0
  #8
Mar 16th, 2005
Originally Posted by atul_manaskar
hi
can u plz tell me the sequence in which after the modem get connected i should flush the streams while transferring data from one end to other.

Modem stop receiving bytes after the follwing events
Data set Ready
Break Interrupt
hi,

did you have any luck finding the problem? (i've looked over the code, but i'm not familiar enough with javax.comm to find anything new)
Quick reply to this message  
Join Date: Mar 2006
Posts: 11
Reputation: nawal is an unknown quantity at this point 
Solved Threads: 0
nawal nawal is offline Offline
Newbie Poster

Re: Connecting modem via java

 
0
  #9
Mar 12th, 2006
hi
I have problem into program previous.
I can connection between two pc with modem using program
previous but , I cannot upload file from pc to pc

please necessary
Quick reply to this message  
Join Date: Dec 2003
Posts: 6,439
Reputation: DMR will become famous soon enough DMR will become famous soon enough 
Solved Threads: 364
Team Colleague
DMR's Avatar
DMR DMR is offline Offline
Wombat At Large

Re: Connecting modem via java

 
0
  #10
Mar 12th, 2006
Hi nawal,


We ask that members not tag their questions on to a thread previously started by another member (regardless of how similar your problem might seem). Not only does it divert the focus of the thread away from the original poster's problem, but it also makes it less likely that you yourself will get the individual attention that you need.

Please start your own thread and post your question there. When you do, please try to give us as much specific info as possible regarding the problem (exact error messages, system specs, etc.).

For a full description of our posting guidelines and general rules of conduct, please see this page:

http://www.daniweb.com/techtalkforum...niweb_policies

Thanks for understanding.
"May the Wombat of Happiness snuffle through your underbrush."
- Ancient Aborigine blessing


Please do not contact me by email or PM for help. We're all volunteers here, and only have so much free time to dedicate to our efforts.

However, if I've been working on a thread with you already, and seem to have "forgotten" your thread, please do send me a message. I try not to let things slip through the cracks, but it does happen sometimes.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC