Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16030
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: serversocket |
| Date | 2012-07-15 00:29 +0000 |
| Organization | UK Free Software Network |
| Message-ID | <jtt2sl$qce$1@localhost.localdomain> (permalink) |
| References | <15b1bc5d-160d-4048-8ad7-2cff9cf862e0@googlegroups.com> <76cf48db-123d-4888-ac60-4b80ccfdeea4@googlegroups.com> <jts9va$r6p$1@dont-email.me> |
On Sat, 14 Jul 2012 10:23:52 -0700, Knute Johnson wrote:
> On 7/14/2012 7:56 AM, Lucyann Lenon Emerick De Assis wrote:
>> translating Good morning!
>> to starting with java but Nevertheless I have some experience with php.
>> Trying to create a ServerSocket with java to get data from the GPS
>> model TK102, did the class below That by the way this "working" I
>> emulei the model of it on my smart and he did what he HAD to read on
>> screen and printed logs , However when i put the gps to connect it does
>> not conect. I know he is working as a forum on the net a guy Gave me
>> the ip of the server and connected it hin. Can someone help me?
>> Em sábado, 14 de julho de 2012 09h41min27s UTC-3, Lucyann Lenon Emerick
>> De Assis escreveu:
>>> Bom dia!
>>> to começando com java mas no entanto já tenho uma certa experiência
>>> com php. to tentando criar um serversocket com java para receber dados
>>> de um gps modelo tk102 , fiz a classe abaixo que por sinal esta
>>> "funcionando" eu emulei o modelo dele no meu smart e ele fez
>>> o que tinha que fazer leu e imprimiu em tela os logs, entretanto
>>> quando eu coloco o gps pra conectar ele nao conect. sei que ele esta
>>> funcionando pois em um forum na net um cara me forneceu o ip do server
>>> dele e nele conectou. alguem pode me ajudar ?
>>>
>>>
>>>
>>> import java.io.BufferedReader;
>>> import java.io.IOException;
>>> import java.io.InputStreamReader;
>>> import java.net.ServerSocket;
>>> import java.net.Socket;
>>>
>>> public class Track {
>>>
>>> public static void main(String[] args) {
>>>
>>> //Declaro o ServerSocket ServerSocket serv = null;
>>>
>>> //Declaro o Socket de comunicação Socket s = null;
>>>
>>> //Declaro o leitor para a entrada de dados BufferedReader
>>> entrada = null;
>>>
>>> while (true) {
>>>
>>> try {
>>>
>>> //Cria o ServerSocket na porta 11000 se estiver
>>> disponível serv = new ServerSocket(11000);
>>>
>>> //Aguarda uma conexão na porta especificada e cria
>>> retorna o socket que irá comunicar com o cliente s =
>>> serv.accept();
>>>
>>> //Cria um BufferedReader para o canal da stream de entrada de dados
>>> do socket s
>>> entrada = new BufferedReader(new
>>> InputStreamReader(s.getInputStream()));
>>>
>>> //Aguarda por algum dado e imprime a linha recebida
>>> quando recebe System.out.println(entrada.readLine());
>>>
>>> //trata possíveis excessões de input/output. Note que
>>> as excessões são as mesmas utilizadas para as classes
>>> de java.io
>>> } catch (IOException e) {
>>>
>>> //Imprime uma notificação na saída padrão caso haja
>>> algo errado.
>>> System.out.println("Algum problema ocorreu para
>>> criar ou receber o socket.");
>>>
>>> } finally {
>>>
>>> try {
>>>
>>> //Encerro o socket de comunicação s.close();
>>>
>>> //Encerro o ServerSocket serv.close();
>>>
>>> } catch (IOException e) {
>>> }
>>> }
>>> }
>>>
>>>
>>>
>>> }
>>> }
>
> A ServerSocket is used when you want to be the server. A Socket is used
> when you want to connect to a server. Is the GPS running a server?
>
I've found a set of variations on a sort-of spec for the TK-102 which
don't shed a lot of light. The thing is a vehicle or person tracker:
you're meant to stick a SIM into it and either interrogate it via SMS or
set it up to send you an SMS at configurable intervals to say where it
is. It also seems to have a microphone that can be used to listen in to
what's happening near it.
It appears that you can also talk to it via its USB socket for
configuration, etc. This assumes you'll use something like a Windows box
running Hyperterminal or a Linux system running minicom or Kermit. I
gather from this that the USB connection must be a serial connection,
which Java does not do without JNI, though I suppose you could use a
socket connection to talk to a TCP:serial converter of some sort.
There is some talk about configuring it with an IPV4 IP, but I frankly
don't understand this unless you can piggyback a TCP session onto GPRS
and/or via an SMS stream and so get to it that way.
In any case it looks very much as though the TK-102 wants to be the
server, so if it can be reached over a socket connection, it looks like
the OP should be using a Socket rather than a ServerSocket to talk to it.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
serversocket Lucyann Lenon Emerick De Assis <lucyann.lenon@gmail.com> - 2012-07-14 05:41 -0700
Re: serversocket Joerg Meier <joergmmeier@arcor.de> - 2012-07-14 16:40 +0200
Re: serversocket Lew <noone@lewscanon.com> - 2012-07-14 13:04 -0700
Re: serversocket Joerg Meier <joergmmeier@arcor.de> - 2012-07-15 00:42 +0200
Re: serversocket Lucyann Lenon Emerick De Assis <lucyann.lenon@gmail.com> - 2012-07-14 07:56 -0700
Re: serversocket Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-07-14 10:23 -0700
Re: serversocket Martin Gregorie <martin@address-in-sig.invalid> - 2012-07-15 00:29 +0000
Re: serversocket Lew <noone@lewscanon.com> - 2012-07-14 14:04 -0700
Re: serversocket Lew <noone@lewscanon.com> - 2012-07-14 14:12 -0700
Re: serversocket Lucyann Lenon Emerick De Assis <lucyann.lenon@gmail.com> - 2012-07-16 04:49 -0700
Re: serversocket Lucyann Lenon Emerick De Assis <lucyann.lenon@gmail.com> - 2012-07-16 04:54 -0700
Re: serversocket Lew <lewbloch@gmail.com> - 2012-07-16 13:59 -0700
csiph-web