![]() |
How to Read from a socket ?? What is the way to read from a socket in Blackberry? I have used the following code to read but it does not reads . for(int i=0;i<length;++i) { input[i] = ((char)in.read()); System.out.println("OUPUT : " +input[i]); } It gets stalled. I tried to use InpuStream.read() but it too does'nt work. Any Suggestions.... |
Re: How to Read from a socket ?? This is the code snipit from the OS 6 API: Code: SocketConnection sc = (SocketConnection) |
Re: How to Read from a socket ?? Yes , that was perfect (y). I was trying to create a server socket in BB Any ideas.... |
Re: How to Read from a socket ?? If you leave out the host name part of the URI in the Connector.open() will return a ServerSocketConnection. You can then use acceptAndOpen to receive connections. The problem is for other systems finding your IP address and connecting. It should work on Wi-Fi, and I have sent UDP packets between BlackBerries on the same carrier, but (at least with my carrier) the phones end up NATed behind the carier's firewall. |
Re: How to Read from a socket ?? Hi, I have to create a server socket for accepting connections. For that how do i get the ip address of the phone (simulator) . I have used the following code to retrieve the ip. { scn = (ServerSocketConnection)Connector.open("socket://:1234"); System.out.println("IP Address----" + scn.getLocalAddress().toString()+"\n"); } But the value if ip its showing blank????? i.e. IP Address---- blank Without the ip connec. can't be created...... |
Re: How to Read from a socket ?? Not all methods of connection are actually implemented by TCP/IP stacks on the phone so there is no IP address associated with the phone in that case. You will need to select a connectiion method that supports an IP address. Not all the connections that support IP addresses are available for the simulator, in fact I'm not sure any are. |
Re: How to Read from a socket ?? Code Snippet public void run() { // Create the server listening socket for port 1234 try{ ServerSocketConnection scn = (ServerSocketConnection)Connector.open("socket://:1234"); // Wait for a connection. SocketConnection sc = (SocketConnection) scn.acceptAndOpen(); // Set application specific hints on the socket. sc.setSocketOption(SocketConnection.DELAY, 0); sc.setSocketOption(SocketConnection.LINGER, 0); sc.setSocketOption(SocketConnection.KEEPALIVE, 0); sc.setSocketOption(SocketConnection.RCVBUF, 128); sc.setSocketOption(SocketConnection.SNDBUF, 128) // Get the input stream of the connection. DataInputStream is = sc.openDataInputStream(); // Get the output stream of the connection. DataOutputStream os = sc.openDataOutputStream(); } catch (Exception e) { System.out.println(e.toString()); } } } |
All times are GMT -5. The time now is 05:15 PM. |
Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.