Re: TLS server-client in Pike
Martin Karlgren <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, Making a guess here: in the read(1024, 1) call in your client, the second argument means "not_all", i.e. it will only return the contents of the input buffer. Perhaps there's simply nothing there yet? Depending on how your application works, you may want to loop or switch to nonblocking (asynchronous) mode. Also, Stdio.FILE (yes, uppercase) may help if you're doing line-based communication. (The difference compared to a normal Stdio.File could be explained by timing issues or implementation details.) /Marty > 1 juni 2016 kl. 17:41 skrev Siddhant Gupta <[email protected]>: > > I am trying to implement a server using tcp which has tls wrapped around it. > This is the code for my server > constant port = 3000; > Stdio.Port mainsock; > SSL.context ctx = SSL.context(); > int main(){ > mainsock = Stdio.Port(); > if(!mainsock->bind(port)){ > write("Error"); > return 1; > } > Stdio.File sock = mainsock->accept(); > SSL.sslfile ssock = SSL.sslfile(sock,ctx); > write(ssock->query_address()); > write("\n"+ssock->is_open()); > ssock->write("test"); > while(1){ > string str = Stdio.stdin->gets(); > ssock->write(str+"\n"); > } > return -1; > } > and this is my client > int main() > { > Stdio.File sock = Stdio.File(); > sock->connect("127.0.0.1",3000); > SSL.sslfile ssl = SSL.sslfile(sock, SSL.context()); > write("Response:\n%s\n", ssl->read(1024,1)); > } > > However I am not getting any message from the server to the client.This works without tls coming in. >