victormedranop Well-Known Member Licensed User Longtime User May 11, 2018 #1 Hi, I just finished an socket apps with MySQL backend. to received data from some devices like GPS and Android phones. But I'm having some troubles when I try to create a client with B4J. if anyone have a sample client socket TCP. thanks, Victor
Hi, I just finished an socket apps with MySQL backend. to received data from some devices like GPS and Android phones. But I'm having some troubles when I try to create a client with B4J. if anyone have a sample client socket TCP. thanks, Victor
Erel B4X founder Staff member Licensed User Longtime User May 13, 2018 #2 Start with this example: [B4X] Network + AsyncStreams + B4XSerializator Upvote 0
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #3 Hi Erel, try the example. but get estrange chars in front of the data. Sending DATA �NB3,imei= I m able to connect and send data but the server refuse because that char any work around? victor Upvote 0
Hi Erel, try the example. but get estrange chars in front of the data. Sending DATA �NB3,imei= I m able to connect and send data but the server refuse because that char any work around? victor
ThRuST Well-Known Member Licensed User Longtime User May 14, 2018 #4 I guess you have to specify the char format in the parameter so look that up. Upvote 0
DonManfred Expert Licensed User Longtime User May 14, 2018 #5 Upload a small project which shoes the issue. I fear that you are using a Textfile which is not UTF8 encoded or maybe it have an BOM. Without seeing your code it is hard to help Upvote 0
Upload a small project which shoes the issue. I fear that you are using a Textfile which is not UTF8 encoded or maybe it have an BOM. Without seeing your code it is hard to help
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #6 it's true donManfred. simple code here. Still Learning. Code: Copy Sub Class_Globals Private astream_client As AsyncStreams Public String2Send As String End Sub Private Sub ConnectToServer(Host As String) Log("Trying to connect to: " & Host) Dim clienttelnet As Socket clienttelnet.Initialize("client") clienttelnet.Connect(Host, 12345, 10000) Wait For Client_Connected (Successful As Boolean) If Successful Then Log("Connect Sucesfully") astream_client.InitializePrefix(clienttelnet.InputStream, False, clienttelnet.OutputStream, "astream_client") SendData(String2Send) Else Log("Failed to connect: " & LastException) End If End Sub Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream.Write(data.GetBytes("UTF8")) astream.Close End Sub Private Sub AStream_client_Terminated LogError("Closing Client Connection") End Sub Private Sub AStream_Client_Error LogError("Astream Error") End Sub Upvote 0
it's true donManfred. simple code here. Still Learning. Code: Copy Sub Class_Globals Private astream_client As AsyncStreams Public String2Send As String End Sub Private Sub ConnectToServer(Host As String) Log("Trying to connect to: " & Host) Dim clienttelnet As Socket clienttelnet.Initialize("client") clienttelnet.Connect(Host, 12345, 10000) Wait For Client_Connected (Successful As Boolean) If Successful Then Log("Connect Sucesfully") astream_client.InitializePrefix(clienttelnet.InputStream, False, clienttelnet.OutputStream, "astream_client") SendData(String2Send) Else Log("Failed to connect: " & LastException) End If End Sub Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream.Write(data.GetBytes("UTF8")) astream.Close End Sub Private Sub AStream_client_Terminated LogError("Closing Client Connection") End Sub Private Sub AStream_Client_Error LogError("Astream Error") End Sub
DonManfred Expert Licensed User Longtime User May 14, 2018 #7 victormedranop said: String2Send Click to expand... you did not show where does the String come from!? Upvote 0
victormedranop said: String2Send Click to expand... you did not show where does the String come from!?
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #8 sorry Code: Copy Dim data As String = "POP,imei=356496043991264&rmc=$GPRMC,140223.00,A,1827.50471,N,06954.75904,W,0.041,,140518,,,A*62,AUTO,G00001,,,,9999,M21,36,4017mV,2.07" Upvote 0
sorry Code: Copy Dim data As String = "POP,imei=356496043991264&rmc=$GPRMC,140223.00,A,1827.50471,N,06954.75904,W,0.041,,140518,,,A*62,AUTO,G00001,,,,9999,M21,36,4017mV,2.07"
DonManfred Expert Licensed User Longtime User May 14, 2018 #9 The Text in your error seems to be another victormedranop said: Sending DATA �NB3,imei= Click to expand... Does not look like the String you posted victormedranop said: Dim data As String = "POP,imei=356496 Click to expand... Upvote 0
The Text in your error seems to be another victormedranop said: Sending DATA �NB3,imei= Click to expand... Does not look like the String you posted victormedranop said: Dim data As String = "POP,imei=356496 Click to expand...
DonManfred Expert Licensed User Longtime User May 14, 2018 #10 Add a log just before sending the String. Convert the String to HEX and log the HEX Output.... This makes it easier to understand what you are really sending.... Upvote 0
Add a log just before sending the String. Convert the String to HEX and log the HEX Output.... This makes it easier to understand what you are really sending....
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #11 This is the full project. the idea is receive some info, sabe in MySQL and connect to other server and send the same data received. I made some server examples but I always receive some trash like this. � Thanks. Victor Last edited: May 14, 2018 Upvote 0
This is the full project. the idea is receive some info, sabe in MySQL and connect to other server and send the same data received. I made some server examples but I always receive some trash like this. � Thanks. Victor
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #12 I traced the connection with tcpdump and this is the result. 10:46:55.464525 IP (tos 0x0, ttl 64, id 39028, offset 0, flags [DF], proto TCP (6), length 60) 67.205.187.213.47578 > 148.103.7.40.12345: Flags , cksum 0x9b60 (incorrect -> 0x591c), seq 2543739037, win 29200, options [mss 1460,sackOK,TS val 107542761 ecr 0,nop,wscale 7], length 0 0x0000: 4500 003c 9874 4000 4006 0716 43cd bbd5 E..<.t@[email protected]... 0x0010: 9467 0728 b9da 3039 979e 609d 0000 0000 .g.(..09..`..... 0x0020: a002 7210 9b60 0000 0204 05b4 0402 080a ..r..`.......... 0x0030: 0668 f8e9 0000 0000 0103 0307 .h.......... 10:46:55.528525 IP (tos 0x0, ttl 64, id 39029, offset 0, flags [DF], proto TCP (6), length 52) 67.205.187.213.47578 > 148.103.7.40.12345: Flags [.], cksum 0x9b58 (incorrect -> 0x368c), seq 2543739038, ack 2845112230, win 229, options [nop,nop,TS val 107542777 ecr 74027], length 0 0x0000: 4500 0034 9875 4000 4006 071d 43cd bbd5 E..4.u@[email protected]... 0x0010: 9467 0728 b9da 3039 979e 609e a994 f7a6 .g.(..09..`..... 0x0020: 8010 00e5 9b58 0000 0101 080a 0668 f8f9 .....X.......h.. 0x0030: 0001 212b ..!+ Upvote 0
I traced the connection with tcpdump and this is the result. 10:46:55.464525 IP (tos 0x0, ttl 64, id 39028, offset 0, flags [DF], proto TCP (6), length 60) 67.205.187.213.47578 > 148.103.7.40.12345: Flags , cksum 0x9b60 (incorrect -> 0x591c), seq 2543739037, win 29200, options [mss 1460,sackOK,TS val 107542761 ecr 0,nop,wscale 7], length 0 0x0000: 4500 003c 9874 4000 4006 0716 43cd bbd5 E..<.t@[email protected]... 0x0010: 9467 0728 b9da 3039 979e 609d 0000 0000 .g.(..09..`..... 0x0020: a002 7210 9b60 0000 0204 05b4 0402 080a ..r..`.......... 0x0030: 0668 f8e9 0000 0000 0103 0307 .h.......... 10:46:55.528525 IP (tos 0x0, ttl 64, id 39029, offset 0, flags [DF], proto TCP (6), length 52) 67.205.187.213.47578 > 148.103.7.40.12345: Flags [.], cksum 0x9b58 (incorrect -> 0x368c), seq 2543739038, ack 2845112230, win 229, options [nop,nop,TS val 107542777 ecr 74027], length 0 0x0000: 4500 0034 9875 4000 4006 071d 43cd bbd5 E..4.u@[email protected]... 0x0010: 9467 0728 b9da 3039 979e 609e a994 f7a6 .g.(..09..`..... 0x0020: 8010 00e5 9b58 0000 0101 080a 0668 f8f9 .....X.......h.. 0x0030: 0001 212b ..!+
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #13 my mistake. in function Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream.Write(data.GetBytes("UTF8")) astream.Close End Sub I was using the server astream. just changed to Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream_client.Write(data.GetBytes("UTF8")) astream.Close End Sub thanks donManfred. always appreciated you help. Victor Upvote 0
my mistake. in function Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream.Write(data.GetBytes("UTF8")) astream.Close End Sub I was using the server astream. just changed to Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream_client.Write(data.GetBytes("UTF8")) astream.Close End Sub thanks donManfred. always appreciated you help. Victor
OliverA Expert Licensed User Longtime User May 14, 2018 #14 This may just be a typo on this board, but Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream_client.Write(data.GetBytes("UTF8")) astream.Close End Sub it looks like you are closing the wrong stream (astream instead of astream_client). Unless you meant to close the other stream. Upvote 0
This may just be a typo on this board, but Code: Copy Public Sub SendData (data As String ) Log("Sending DATA " & String2Send) astream_client.Write(data.GetBytes("UTF8")) astream.Close End Sub it looks like you are closing the wrong stream (astream instead of astream_client). Unless you meant to close the other stream.
victormedranop Well-Known Member Licensed User Longtime User May 14, 2018 #15 True. Thanks. Victor Upvote 0