Forum > Packages and Libraries

synapser send file by tcip

(1/2) > >>

eldonfsr:
I just started with a small app, before i was using synapser serialcom but now i wanna send file also by tcpip, i read information but a i am lite confouse if i have to bind the ip sending and received, or is only pc to pc by net cable, pls helpme with some ideas pls.

eldonfsr:
After some test i got connect 2 pc on my local net but the problem is i don get received nothing, i dont know if only is posible to work with ip: 127.0.0.1 or localhost or i have to use cable cruz fot connect both pc he my source, tell me and help me if i doing something wrong

on client conection:
procedure TFormAction.Button2Click(Sender: TObject);
var   mysock:TTCPBlockSocket;
      s,m:string;
begin
  mysock := TTCPBlockSocket.Create;
  mysock.ConvertLineEnd := True;
  mysock.Connect ('192.168.1.103', '12345');
//This will read a line terminated by #A0 (LF) or #D0A0 (CRLF)
//  m := mysock.RecvString (30000); //read welcome message
  if mysock.LastError= 0 then
   begin
     mySock.Accept;
     mysock.SendString ('USER me'+CRLF); //you must send CRLF yourself
     mysock.SendString ('USER me'+CRLF);
     mysock.SendString ('USER me'+CRLF);
     mysock.SendString ('USER me'+CRLF);
     s:=mysock.RecvPacket (20000);
     s:='PASS dontknow'+CRLF;
     mysock.SendBuffer (pointer(s), length(s));
     setlength (s, mysock.WaitingData);
     if s<>'' then
      mysock.RecvBuffer (@s[1], length(s));
      mysock.CloseSocket;
      mysock.Free;
     end
  else
    begin
     showmessage( 'Error connection '+inttostr(Mysock.LastError)+' '+ MySock.LastErrorDesc);
    end;
end;

BigChimp:
If connecting to pcs directly to each other you would need cross cables yes.

I would first rule out problems on lower levels: can the pcs ping each other? Try exchanging data with netcat or an existing chat program and see if it works.
Make sure firewalls for the relevant ports are set to allow traffic.

Also: which operating system are you using?

I'll leave comments on the source code to others, but you're only showing the client part. What are you trying to connect to on the server part? An existing server? What kind of server: ftp, scp,... Or your own server?
The synapse website has examples; there are alos examples on the Synapse page in the Lazarus wiki... and there are probably quite some in this forum as well.

ludob:
mySock.Accept; is only used on the server after a listen, never on a client.
The mySock clean up code is completely wrong. mySock is only closed and freed when mysock.WaitingData is >0 which will probably never happen because you check it immediately after a SendBuffer.
A basic tcp client looks like this:

--- Code: ---var
  sock: TTCPBlockSocket;
  bufout,bufin: string;
begin
  sock := TTCPBlockSocket.Create;
  try
    sock.connect('192.168.1.103', '12345');
    if sock.LastError = 0 then
      begin
      // your code here. for example
      sock.SendString(bufout);
      bufin := sock.RecvPacket(3000);
      //
      sock.CloseSocket;
      end;
  finally
    sock.free;
  end;
end;
--- End code ---
There is no reason to use mysock.ConvertLineEnd when you explicitly add CRLF yourself. It will also mess up binary data that you might want to transfer .

For a simple TCP server look at the echo demo that comes with synapse in the demos directory.


--- Quote ---i dont know if only is posible to work with ip: 127.0.0.1 or localhost or i have to use cable cruz fot connect both pc he my source
--- End quote ---
Before worrying about cables, test your code by running your server and client on the same machine. Let the client connect to '127.0.0.1','12345'. Only when everything works well, try your program on 2 machines.
Cross over cables are needed on older hardware. More and more computer network interfaces integrate Auto-MDIX which means that you can use standard patch cables. Having one Auto-MDIX interface card on either side of the cable is enough.

BigChimp:

--- Quote from: ludob on April 14, 2012, 10:23:34 am ---Cross over cables are needed on older hardware. More and more computer network interfaces integrate Auto-MDIX which means that you can use standard patch cables. Having one Auto-MDIX interface card on either side of the cable is enough.

--- End quote ---
Live and learn ;)

Navigation

[0] Message Index

[#] Next page

Go to full version