We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCP/IP Socket Programming
#1
Hello, i want to program a TCP/IP Socket to establish an ethernet communication, just to transmit some values over ethernet.
I look for some example codes or API or libraries in litdev. 
Who can give me a hint ?
Reply
#2
For http Web requested look at ldnetwork.  For network communications look at ldserver and ldclient.

I am away from home at present without pc, but I think there are some samples for these with the extension download.

If you use sb prime then you can also search extensions.

Not sure exactly what you are after, but I think the ldserver ldclient is most likely.
Reply
#3
Thanks for your help, i think LDServer and LDClient is what i need. Can you give me a link to some examples where they are used ?
Thanks
Reply
#4
(07-16-2025, 09:40 AM)Juergen Wrote: Thanks for your help, i think LDServer and LDClient is what i need. Can you give me a link to some examples where they are used ?
Thanks

Hello! Shy

Here is a link to the examples folder:

https://github.com/litdev1/LitDev/tree/m...ent-server
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
#5
I am programming a program for my Pc connecting to a device that control a model railway. I think this device is the server and my PC is client. In the description of this device it is declared that it has an ethernet with a IP 192.168.2.20 and a recieve Port 15730 and a send Port 15731. Now my question : do i have to connect to both ports with :
LDClient.Connect( "192.168.2.20:15730", "False" ) and LDClient.Connect( "192.168.2.20:15731", "False" ) , or only connect to the recieve Port 15731 ?
Reply
#6
Hi,

I've only used the Client/Server with both client and server being Small Basic programs, so not fully sure.

If the server is using different ports to send and receive data, then I think you may need 2 separate SB programs to connect to each.  

I guess I would start by tring to send a message to 192.168.2.20:15731 in a simple SB program and check if this gets through.  If this works it is a good start.

To receive messages use the LDClient.ServerMessage event and property LDClient.LastServerMessage, but I think this will have to be a separate SB program connected to 192.168.2.20:15730.

If these work independently, then I would think that one of the 2 SB programs would be the master and the other would be a slave that is controlled by the master, perhaps through a common file.
Reply
#7
thanks for information, the device i am connected with i can not modify only i can put in an other ip adress , nothing more. And on my pc i have only one program with i want to send and recieve messages. so i thing i have to connect to both ports if i understand you correctley.
Reply
#8
Yes, but I am only guessing to some extent.  I would test the sending and receiving separately on very small test SB programs using the different ports as I suggested.

Once these both work independently, we can consider how to use both together - I suspect this will have to be 2 SB programs, but I can help suggest ways to run them together when you get to that point.
Reply
#9
can you tell me if this syntax is correct ?

If LDClient.CheckServer( "192.168.0.96:15731" ) = "AVAILABLE" THEN
LDClient.Connect( "192.168.0.96:15731", "TRUE" )
CS_Recieveport_connected = 1
EndIf
Reply
#10
Yes, that should work (syntax is right if it compiles - whether it does what you expect is a different thing - that depends what you expect!) - I wouldn't use the "True" on the Client connection - that is for use with LDServer.

Before even using the If test, just print out the result - you can add frills when the basics work.

Code:
TextWindow.WriteLine("Testing...")
result = LDClient.CheckServer("192.168.0.96:15731")
TextWindow.WriteLine(result)

If it fails there is a few seconds delay where a timeout is applied.

Or you could just check the client connection:

Code:
result = LDClient.Connect("192.168.0.96:15731", "False")
TextWindow.WriteLine(result)
Reply


Forum Jump:


Users browsing this thread: stevantosic, 1 Guest(s)