[Gambas-user] Problmes with sockets
Daniel Campos
danielcampos at ...282...
Mon Jul 11 08:45:56 CEST 2005
You must specify the event handlers, that is, you can do, for example:
Public Srv As ServerSocket
Srv=NEW ServerSocket AS "Srv"
So you can use:
PUBLIC SUB Srv_Connection(sHost As String)
...
END
The same thing with the client:
Public Sock As Socket
Sock=New Socket AS "Client"
...
PUBLIC SUB Client_Ready()
..
END
Regards,
D. Campos
PaquitoSoft escribió:
>Hello!!
>
>How do you do? I'm having a terrible headache because of sockets. I'm
>starting with them and it seems as they were trynig to beat me, but I
>resist as much as I can... (god, what the hell I'm saying!! sorry)
>
>The fact is... I'm trying to connect a client with a server; easy, isn't
>it?
>My client would have a lot of outgoing connections at the same time, and
>the server, of course will have a lot of incoming ones.
>
>I started the client, trying it against the Server gambas example. And
>here is where I'm stucked.
> I make the connection with .connection() method and the server receives
>it and accepts it. But, none of the sockets events are raised in the
>client side.
>I don't use form control. I mean I didn't put a Socket into my form.
>Since a will have many of them, I create them anytime a I need one and
>sotred them in a Collection..
>This is what I'm trying:
>
>
>' Gambas class file
>PUBLIC srvSocket AS ServerSocket
>PUBLIC serverConnectionSck AS Socket
>PUBLIC sockets AS Collection
>PUBLIC idSocket AS Integer
>
>PUBLIC CONST LOCAL_PORT AS Integer = 40004
>PUBLIC CONST SERVER_PORT AS Integer = 30003
>PUBLIC CONST SERVER_HOST AS String = "10.10.10.10"
>
>PUBLIC SUB _new()
> sockets = NEW Collection
> srvSocket = NEW ServerSocket
> srvSocket.Type = NET.Internet
> srvSocket.Port = 40004
>
> serverConnectionSck = NEW Socket
> serverConnectionSck.Host = SERVER_HOST
> serverConnectionSck.Port = SERVER_PORT
>
> sockets.add("0",serverConnectionSck)
>
> idSocket = 0
>END
>
>PUBLIC SUB Aux_click()
>
> serverConnectionSck.Connect()
>
> CATCH
> PRINT "Error: " & Error.Text & " en la línea -> " & Error.Where
>
>END
>
>
> '***************** SERVER EVENTS ****************'
>PUBLIC SUB Socket_Found()
> PRINT "Host found..."
>END
>
>PUBLIC SUB Socket_Closed()
>'This event is raised when the server close the connection
> PRINT "Server has closed the connection"
>END
>
>PUBLIC SUB Socket_Ready()
> PRINT "Connection stablished sucessfully "
>END
>
>
>PUBLIC SUB Socket_Error()
> PRINT "Error: " & MAux.getStateMessage(serverConnectionSck.Status)
>END
>
>PUBLIC SUB Socket_Read()
>
> DIM info AS String
>
> READ #LAST, info, Lof(#LAST)
> PRINT dinfo
>
>END
>
>Well, actually I only want this program show me a message after it tries
>to connect. I expect it to print that the connection was stablished, but
>it doesn't print anything.
>On the server side it recieves the connection and accepts it, but in the
>client side it doesn't happen anything after
>serverConnectionSck.Connect().
>
>Any ideas??
>
>Thanks a lot!!
>
>
>
More information about the User
mailing list