Anyone have any two way socket tutorials

BlitzMax Forums/BlitzMax Beginners Area/Anyone have any two way socket tutorials

*(Posted 2007) [#1]
I have had a look at http://www.blitzbasic.com/Community/posts.php?topic=47877 any have a one way communication working just was wondering about two way communication from the server to the client.

Basically I need different ports on a connection, atm I have the client connecting to the server perfectly on a given port now I want the server to connect to the client on another port. Any tutorials on the subject would be greatly appreciated.


rdodson41(Posted 2007) [#2]
Check out my network module vvv see sig vvv that makes this a bit easier.
I can post an example if you want, but basically you create a server and then connect to it with a client, and you can use the normal WriteInt and ReadInt type commands to read and write data.


*(Posted 2007) [#3]
If ya could post a basic example it would be greatly appreciated.


AltanilConard(Posted 2007) [#4]
You don't need two ports for two way communication from to client to server, if you particulary want 2 ports then don't mind this example:

Client:
Global client:TClient
Global sendbank:TBank
Global receivebank:TBank

Graphics 320,240

client=TClient.Create("localhost",112233)
If Not client RuntimeError "Could not connect to the server!"
sendbank=CreateBank(500) ; receivebank=CreateBank(500)
For i=0 To 500-1
	PokeByte sendbank,i,0
Next
PokeByte sendbank,0,7

While Not KeyHit(KEY_ESCAPE)
	If KeyHit(KEY_S)
		WriteBank(sendbank,client,0,500)
	EndIf
	DrawText "updating",0,0 ; Flip ; Cls
	If client.readavail() > 400
		ReadBank(receivebank, Client, 0, 500)
		Notify "received packet"
	EndIf
Wend


Server:
Global server:TServer
Global client:TClient
Global clients:TList
Global receivebank:TBank

Graphics 320,240

server=TServer.Create(112233)
clients=CreateList()
receivebank=CreateBank(500)

While Not KeyHit(KEY_ESCAPE)
	client=server.Accept()
	
	If client
		Print "New Client"
		ListAddLast(clients,client)
	EndIf
	
	For client=EachIn clients
		If client.ReadAvail() > 400 Then
			as=ReadBank(receivebank,client,0,500)
			Print PeekByte(receivebank,0)
		EndIf
	Next
	
	If KeyHit(KEY_S)
		For i=0 To 500-1
			PokeByte(receivebank,i,0)
		Next
		WriteBank(receivebank,client,0,500)
	EndIf
	
	DrawText "Clients online: " + CountList(clients),0,0
	
	Flip
	Cls
Wend


In both examples you will have to add rich d's code.
It uses databanks to send packets from client to server. If you press 'S' on the server the client will notify you it has received a packet, if you press 'S' on the client the server will print the first byte of the packet.
Ofcourse you don't have to use databanks, it's just that I find it more comfortable like that.


*(Posted 2007) [#5]
Thanks will have a look at it :)